Why does adjusting physics.setTimeStep() change the trajectory?

As I understood it, physics.setTimeStep(…) will speed up or slow down the physics operations, which is great. But why does it also change the path things will take in the word, like the bounce off, trajectory and such? Shouldn’t it be doing the same, but merely faster/ slower? How would I get it to do that? Thanks!

+1. I’ve used Box2D before and with a fixed time step such as physics.setTimeStep(1/30) and physics.setTimeStep(1/60), should both have the same trajectory, but from my test cases it seems it completely changes.

Any help on this?

EDIT: Just wanted to say I was wrong on this. I need Corona to implement a way of forcing the next timestep so I can use the physics engine to calculate the trajectories. The way I did it before was like this: (objective-c)

 while(timeToRun \>= fixedTimeStep) { int32 velocityIterations = 8; int32 positionIterations = 1; world-\>Step(fixedTimeStep, velocityIterations, positionIterations); CGPoint position = ccp(bullet-\>GetPosition().x, bullet-\>GetPosition().y); } 

This way during one frame the engine will show the bullet’s positions all at once.

PLEASE ADD IN physics.nextStep(dt) :smiley:

I need this to finish or I’ll have to switch over to something like Unity.

There could be a bunch of things going on, but I would guess that this is a byproduct of the time integration scheme … if you use larger time-step sizes, you get faster computation but less accurate answers.  Depending on your velocity, acceleration, etc., those errors might be visible.

Box2D may not be using this specific method, but all of them are subject to the same kinds of errors:

In the picture, the red A1-A2-A3 curve is slowly drifting from the correct answer (the blue line).  If you increase the time-step size, the A1-A2-A3 curve would get even worse.

Hmmm interesting. I think you’re right, however I don’t see how there’s any way to fix my problem given the current physics API.

Basically I need to show an EXACT projection of what will happen when the user shoots the ball at the cannon’s current angle. I know I could do some of the physics math myself, but were talking about something that will calculate trajectories past multiple collisions.

Any ideas on how I can do this?

+1. I’ve used Box2D before and with a fixed time step such as physics.setTimeStep(1/30) and physics.setTimeStep(1/60), should both have the same trajectory, but from my test cases it seems it completely changes.

Any help on this?

EDIT: Just wanted to say I was wrong on this. I need Corona to implement a way of forcing the next timestep so I can use the physics engine to calculate the trajectories. The way I did it before was like this: (objective-c)

 while(timeToRun \>= fixedTimeStep) { int32 velocityIterations = 8; int32 positionIterations = 1; world-\>Step(fixedTimeStep, velocityIterations, positionIterations); CGPoint position = ccp(bullet-\>GetPosition().x, bullet-\>GetPosition().y); } 

This way during one frame the engine will show the bullet’s positions all at once.

PLEASE ADD IN physics.nextStep(dt) :smiley:

I need this to finish or I’ll have to switch over to something like Unity.

There could be a bunch of things going on, but I would guess that this is a byproduct of the time integration scheme … if you use larger time-step sizes, you get faster computation but less accurate answers.  Depending on your velocity, acceleration, etc., those errors might be visible.

Box2D may not be using this specific method, but all of them are subject to the same kinds of errors:

In the picture, the red A1-A2-A3 curve is slowly drifting from the correct answer (the blue line).  If you increase the time-step size, the A1-A2-A3 curve would get even worse.

Hmmm interesting. I think you’re right, however I don’t see how there’s any way to fix my problem given the current physics API.

Basically I need to show an EXACT projection of what will happen when the user shoots the ball at the cannon’s current angle. I know I could do some of the physics math myself, but were talking about something that will calculate trajectories past multiple collisions.

Any ideas on how I can do this?