Page 1 of 1

Simulate arrow flight

Posted: Tue Aug 28, 2012 4:09 am
by indeed005
Hi All,

I have a 3D game I am working on in XNA using bepu Physics (which has been EXCELLENT so far, thanks Norbo). I am trying to make arrows fly. The arrow's collidable is a Box prefab entity scaled in such a way as to fit the arrow's graphical representation.
I initially set the WorldTransform (and therefore the orientation) of the arrow only when it was first fired. Which is fine if I am only interested in straight line flight paths. But I am now trying to update the orientation of the arrow each frame such that it always heads in the direction of the current (normalized) LinearVelocity vector. I created a lookat matrix for the direction of the velocity and converted it to a quat, and set the orientation to this quat. It didn't work, in some directions the arrow flew sideways, and yawed direction as it dropped (as opposed to pitching). The arrow's world model is transformed straight from the WorldTransform property of its collidable.
The question is: is the linear velocity relative to the orientation of the collidable in any way? (or vice versa, if you like)
All help appreciated

Re: Simulate arrow flight

Posted: Tue Aug 28, 2012 4:33 am
by Norbo
I have a 3D game I am working on in XNA using bepu Physics (which has been EXCELLENT so far, thanks Norbo).
Glad to hear it! :)
is the linear velocity relative to the orientation of the collidable in any way? (or vice versa, if you like)
Linear velocity is in world space. That is, if an object has a linear velocity of (1,0,0), the Position will increase by (1,0,0) per second, regardless of orientation.

What might be happening is the method you're using to create the look at matrix is generating a view matrix. View matrices used by cameras can be thought of as pulling objects from world space into camera space, where the camera is at (0,0,0) and pointing along an axis. In other words, the view matrix of a camera is the inverse of its world matrix. If the quaternion was created from a view matrix, the orientation will be inverted from what you want.

If this is the issue, invert the orientation before giving it to the entity or create the matrix originally using something like Matrix.CreateWorld instead of Matrix.CreateLookAt.

Re: Simulate arrow flight

Posted: Wed Aug 29, 2012 2:53 am
by indeed005
Ok, I feel silly -- sigh -- I should have known that. Yup, Inverted the quat, thanks Norbo!