schteppe / p2.js

JavaScript 2D physics library
Other
2.64k stars 330 forks source link

How to dilate a Body & let it 'kick' another body? #277

Closed finscn closed 7 years ago

finscn commented 7 years ago

I change the radius of a circle quickly , I want to it could kick other bodies.

But I found the power/force of the circle is too small.

How can I do that : if the radius of a circle change slowly , the power is small; if dilated quickly , the power is big ?

schteppe commented 7 years ago

Hi. The radius of a circle does not have dynamics, which means that it doesn't use velocity or force to update itself. It's assumed to be constant. In fact, the definition of "rigid body physics" states that geometry should be rigid and not change...

This said, you'll have to apply the needed forces or pulses manually. You could get the contact normal and use that to compute the "kick force"..

finscn commented 7 years ago

Thanks .

Another question : if I've computed the "kick force" , how to apply to the body which will be kicked?

Use appleForce or applyImpulse ? What's different between them?

Thank you very much.

schteppe commented 7 years ago

@finscn .applyForce is usually used to add forces during a longer time (for example gravity or springs), while .applyImpulse is used to add an instantaneous "kick" to an object (for example when hitting a ball with a baseball bat). To me it sounds like you want .applyImpulse()

finscn commented 7 years ago

Yes. Thanks very much!