Page 1 of 1
rotate on y axis
Posted: Wed Nov 20, 2013 11:00 pm
by Jack Burton
hi furthering my endeavours with xna and bepu I am trying to simulate a model rotating on the y axis only when i press the corresponding key. whats the best way of going about this
thanks
Re: rotate on y axis
Posted: Wed Nov 20, 2013 11:29 pm
by Norbo
Setting entity.AngularVelocity = new Vector3(0, 1, 0) will make the entity rotate around the Y axis at 1 radian per second. Setting it to (0,0,0) will make it stop rotating. That's all you have to do in response to the input if you're using a kinematic entity.
If you want to use a dynamic entity, it'll just fall over or stop moving due to friction after you set the velocity. To solve this, the usual approach would be constraints. For example, a RevoluteJoint could be used with the free axis set to (0, 1, 0). Setting the entity's velocity would still work in this case, but the RevoluteMotor in the RevoluteJoint would let you control it a little more physically.
Re: rotate on y axis
Posted: Wed Nov 20, 2013 11:46 pm
by Jack Burton
thanks Norvo
I was trying to do it with the AngularVelocity but I wasn't achieving the effect I wanted
This is the code I had Ill try AngularVelocity back to (0,0,0) once the key is not pressed see if that works.
Ultimatly im try to simulate the controls of an aeroplan
Code: Select all
if (KeyboardState.IsKeyDown(Keys.D))
{
player.playerWorld = Matrix.CreateFromAxisAngle(Vector3.Up, .02f) * player.playerWorld;
player.shipColBox.AngularVelocity = new Vector3(0,-1,0);
}
Re: rotate on y axis
Posted: Thu Nov 21, 2013 12:04 am
by Norbo
Airplane controls should be handled quite a bit different than what I mentioned- using the plane's local up for velocity changes would probably be what you want for yawing behavior.
So, something like this executed each frame would probably be closer:
Code: Select all
airplaneEntity.AngularVelocity += airplaneEntity.OrientationMatrix.Up * (yawAcceleration * dt);
Then you'd need to tune yawAcceleration and probably limit the maximum speed. (For reference, Vector3.Dot(entity.AngularVelocity, normalizedDirection) tells you how fast the entity is rotating around normalizedDirection. You can use this to implement a speed cap.)
There are a bunch of other possible approaches too, both up and down the 'realism' ladder. Which one you should use depends on the desired behavior.
Re: rotate on y axis
Posted: Thu Nov 21, 2013 11:05 pm
by Jack Burton
Thanks Norbo that worked a treat
