Rotating an object and not efecting direction

Discuss any questions about BEPUphysics or problems encountered.
Post Reply
ApppStudio
Posts: 9
Joined: Thu Jul 27, 2017 12:28 pm

Rotating an object and not efecting direction

Post by ApppStudio » Wed Aug 30, 2017 2:18 pm

Hi Guys,

I have hit a bit of an issue and I think my matrix maths is the problem. I have a hover board in my game which moves and floats well (thanks norbo) I am now trying to lift the front when the player moves forward I thought this was going to be simple by applying a small X rotation to the orientation matrix but this causes 2 issues firstly it wipes the existing rotation values and secondly this make the boards forward vector move up as well is the any way of adding the rotation matrix and also for it to not effect the forward vector? Hope that makes sense

Norbo
Site Admin
Posts: 4558
Joined: Tue Jul 04, 2006 4:45 am

Re: Rotating an object and not efecting direction

Post by Norbo » Wed Aug 30, 2017 8:12 pm

'Wiping' the existing rotation shouldn't be an issue when applying an incremental rotation around a local axis, like so:

Code: Select all

                    entity.OrientationMatrix *= Matrix3x3.CreateFromAxisAngle(toAdd.OrientationMatrix.Right, MathHelper.PiOver4 * dt);
However, the only axis of rotation that won't change the forward vector for any angle is a rotation around the forward vector- in other words, rolling. There is no way for any other nonidentity rotation to not change the forward vector.

If you want a horizontal forward direction, you could project the forward vector onto the desired horizontal plane. For example, if you want to consider only a forward direction along the X and Z axes, then you can just zero the forward's Y component. You can renormalize it if needed, but be careful about the case where the forward vector is parallel with the Y axis- the projected direction would have zero length and normalization would result in nans. In that case, you can pick an arbitrary direction instead.

As a side note, be careful with direct modification of the orientation or position of entities. It's a nonphysical action with no associated velocity, so collision response won't work as expected. It will seem very squishy and prone to penetration. To avoid this, try to control objects at the velocity or force level instead.

Post Reply

Who is online

Users browsing this forum: Baidu [Bot] and 1 guest