Reputation: 399
I'm using body.setTransform to move some of my objects around. I know it's bad, but it is just the way it needs to be in my case - bodies follow certain paths. When such a body is hit by a bullet it stops moving on the path (body.setTransform() is no longer called) and it lets physics act.
The problem is that sometimes the body freaks out - it seems like the contact force etc. is applied to different body values (coordinates etc). As a result it starts spinning and flies throw other bodies.
It is clearly the problem with body.setTransform(), because when I turn moving on path off all physics is fine. My google findings also confirm that body.setTransform() may screw up physics.
I was trying to set all velocities to 0 after a contact. That cancels the contact impact and the body doesn't move. But its 'physic data' seems to be still corrupted - it doesn't act right when it is hit with something afterwards.
Is there any way to 'reset' a body that was tempered with using body.setTransform() so that it acts properly again?
Upvotes: 2
Views: 1884
Reputation: 24846
Use b2MouseJoint
to move the body along the path and preserve correct physical behaviour.
Upvotes: 2