applyImpulse relative to object #11

rscottfree opened this Issue May 11, 2012 · 3 comments

2 participants


First, awesome job on this library, very easy to use.

And second, a question/feature request: I have been playing around with applying an impulse on an object with applyCentralImpulse(). I am applying a positive impulse on the Y axis like rocket.applyCentralImpulse(new THREE.Vector3(0, 1e3, 0)). This is the rocket taking off. But then I rotate my rocket on the Z axis, and I want to apply the same impulse, but now propel my rocket in the direction it is facing (instead of just up on the Y world axis). In other words, I want to propel my rocket on it's own Y axis.

I'm new to matrices and physics in general, but I have some idea that I need to take my force vector and somehow convert that into my objects direction vector (maybe the cross product of my direction and force vectors?). It doesn't appear there is a ready-made function to apply an impulse to an object relative to it's own XYZ, but maybe you could point me in the right direction as to how one would accomplish this?


After a lot of messing around and some help from someone who actually knows physics, I found out how to do this--it's pretty simple, actually.

If you have a force, like Vector3(0, 100, 0), you can apply that to an object relative to itself by multiplying it by the object's matrix.

So, if you have a box mesh, box, and your force, var force = THREE.Vector3(0, 100, 0), you do something like this to get the actual force you are going to apply to the box:

var newForce = box.matrix.multiplyVector3(force);

This will apply the force in the Y direction of the object instead of the Y direction of the scene.

@rscottfree rscottfree closed this May 12, 2012

You beat me by an hour :) I'm glad the solution I was thinking of is what worked for you, haha.

Enjoy the library!


Actually, the way I did this turned out to cause me a lot of head-scratching issues (like velocities getting out of control). For an explanation of how I got this working, see this comment on a related issue.

In short, you have to extract the rotation matrix of the object and multiply the force vector by that, then apply the resulting vector back to your object.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment