Best way to move kinematic object

Hi,

which is the best way to move a kinematic physic body? Increase its position or set a constant speed?

Thanks in advance.

-j

Never set the .x,.y values of physics objects - you’re breaking the fundamental rules of the engine.

If you really need to do that, switch off the physics body (.isBodyActive=false), move it, then turn the body back on. I’m not sure, but you might need to use a timer to turn the body back on. 1 millisecond should be enough.

The best way to move a physics body is to attach a touch joint and use setTarget().  Play around with the values of the joint to get the right pull and you should be able to set the object’s position very accurately.

As I often advise, if you’re already using the physics engine, use it to its full capacity. In other words, there’s not often a reason to update an object’s position via a Runtime enterFrame cycle when you can just apply a velocity to it and let the physics engine do its task.

As a side note, remember that kinematic bodies don’t accept force-based actions, including gravity. So, you can set a direct linear velocity on them, but you can’t apply force or impulse to them.

Brent

Never set the .x,.y values of physics objects - you’re breaking the fundamental rules of the engine.

If you really need to do that, switch off the physics body (.isBodyActive=false), move it, then turn the body back on. I’m not sure, but you might need to use a timer to turn the body back on. 1 millisecond should be enough.

The best way to move a physics body is to attach a touch joint and use setTarget().  Play around with the values of the joint to get the right pull and you should be able to set the object’s position very accurately.

As I often advise, if you’re already using the physics engine, use it to its full capacity. In other words, there’s not often a reason to update an object’s position via a Runtime enterFrame cycle when you can just apply a velocity to it and let the physics engine do its task.

As a side note, remember that kinematic bodies don’t accept force-based actions, including gravity. So, you can set a direct linear velocity on them, but you can’t apply force or impulse to them.

Brent