Closed mbchang closed 8 years ago
This is because body.velocity
is read-only. Instead if you want to control velocity you should specify a body.positionPrev
since velocity is derived using body.position - body.positionPrev
during Verlet integration. So an example to give a body a velocity of (5, 5)
:
Bodies.rectangle(400, 90, 10, 10, {
positionPrev: { x: 400 + 5, y: 90 + 5 }
});
You could also use Body.setVelocity
after creation. I realise this isn't obvious or convenient. It would be cool to make body.velocity
set-able but by nature of the integration method it would be tricky.
I see, it works now. Thank you!
I am trying to generate some object trajectories given nonzero initialized velocities. In the first time step, the objects move fine according to these velocities, but immediately in the next timestep the velocities are reset to 0. I had expected those objects to follow their inertial path and continue moving at their original velocities until a collision. Is there something I need to do to have the objects maintain inertial movement?
Below is a minimal example based on the Demo:
The output of which is: