This is my first post on these forums.
Anyway I have a body and I only want it to move up,down,left, and right. Never diagonal. I use setLinearVelocity to accomplish this but the body still moves diagonally sometimes.
To prove it I used this code around my _world step:
NSLog(@"linear velocity: %f %f", mybody->GetLinearVelocity().x, mybody->GetLinearVelocity().y);
NSLog(@"the x1, y1: %f %f", mybody->GetPosition().x, mybody->GetPosition().y);
_world->Step(dt, velocityIterations, positionIterations);
NSLog(@"the x2, y2: %f %f", mybody->GetPosition().x, mybody->GetPosition().y);
I have my ship moving down using ship->setLinearVelocity(0,-3). Then I make it move left by using setLinearVelocity(-3,0) and when I'm done it prints off this:
linear velocity: -3.000000 0.000000
the x1, y1: 2.144350 4.124759
the x2, y2: 2.063884 4.086793
linear velocity: -3.000000 0.000000
the x1, y1: 2.063884 4.086793
the x2, y2: 1.982696 4.073295
linear velocity: -3.000000 0.000000
the x1, y1: 1.982696 4.073295
the x2, y2: 1.915824 4.062496
linear velocity: -3.000000 0.000000
the x1, y1: 1.915824 4.062496
the x2, y2: 1.865070 4.062496
As you can see even though the program acknowledges that my linear velocity is set to -3,0. It still moves my ship slightly in the downward direction before plateau-ing at the value of 4.062496.
When you go from setLinearVelocity(0,-3) to setLinearVelocity(-3,0) does it take the body a few world steps to stop moving left, thus allowing it to move momentarily diagonally?? And if so how do I make it stop doing that?
Thanks for any help, and I can clarify more if this post is confusing.
EDIT: Moved to general discussion because this was the wrong place
Anyway I have a body and I only want it to move up,down,left, and right. Never diagonal. I use setLinearVelocity to accomplish this but the body still moves diagonally sometimes.
To prove it I used this code around my _world step:
NSLog(@"linear velocity: %f %f", mybody->GetLinearVelocity().x, mybody->GetLinearVelocity().y);
NSLog(@"the x1, y1: %f %f", mybody->GetPosition().x, mybody->GetPosition().y);
_world->Step(dt, velocityIterations, positionIterations);
NSLog(@"the x2, y2: %f %f", mybody->GetPosition().x, mybody->GetPosition().y);
I have my ship moving down using ship->setLinearVelocity(0,-3). Then I make it move left by using setLinearVelocity(-3,0) and when I'm done it prints off this:
linear velocity: -3.000000 0.000000
the x1, y1: 2.144350 4.124759
the x2, y2: 2.063884 4.086793
linear velocity: -3.000000 0.000000
the x1, y1: 2.063884 4.086793
the x2, y2: 1.982696 4.073295
linear velocity: -3.000000 0.000000
the x1, y1: 1.982696 4.073295
the x2, y2: 1.915824 4.062496
linear velocity: -3.000000 0.000000
the x1, y1: 1.915824 4.062496
the x2, y2: 1.865070 4.062496
As you can see even though the program acknowledges that my linear velocity is set to -3,0. It still moves my ship slightly in the downward direction before plateau-ing at the value of 4.062496.
When you go from setLinearVelocity(0,-3) to setLinearVelocity(-3,0) does it take the body a few world steps to stop moving left, thus allowing it to move momentarily diagonally?? And if so how do I make it stop doing that?
Thanks for any help, and I can clarify more if this post is confusing.
EDIT: Moved to general discussion because this was the wrong place