Gravity Gun

Gravity Gun

Technically this doesn't apply to JUST the gravity gun, but I just implemented the gravity gun into my little engine demo. Now since I'm using DirectX, I'm in the left hand co-ordinate system. If I pass the gravity gun my view transform as-is from DirectX, it doesn't work. Right now I have a little hack going on that corrects all the little bugs, but it still leaves some functionality out (like being able to grab objects in my vertical axis).Basically I'm wondering if anyone has implemented this before with DirectX, or if there is some wasy way for me to give it exactly what it wants.Thanks in advance,Daniel

3 posts / 0 new
Last post
For more complete information about compiler optimizations, see our Optimization Notice.
Best Reply

Generally, your chosen coordinate system should not matter since Havok is not inherently right or left handed. So long as you are consistent with your coordinate system everything should be fine.

hkpGravityGun however, does need to make an assumption about which direction is 'forward', and it happens to choose the X axis of the 'view frame' passed in. Here's an example of how to set up an hkTransform that will make hkpGravityGun happy:

void createGunViewFrame( hkTransform & gunViewTransformOut, hkVector4 const& characterPosition,

                      hkVector4 const& characterUp, hkVector4 const& characterForward )


	gunViewTransformOut.setTranslation( characterPosition );
	hkVector4 x = characterForward;

	hkVector4 y = characterUp;

	hkVector4 z;

	z.setCross(x, y); z.normalize3();

	y.setCross(z, x); y.normalize3();

	gunViewTransformOut.getRotation().setCols(x, y, z);


Hope that helps!

Thank you SO much Tyler. This worked flawlessly, and exactly how I wanted it to. I guess trying to pass it the DirectX view transform created a lot of inconsistensies.Once again, thank you.-Daniel

Leave a Comment

Please sign in to add a comment. Not a member? Join today