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
rotate on y axis
Re: rotate on y axis
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.
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.
-
- Posts: 12
- Joined: Sun Nov 03, 2013 9:29 pm
Re: rotate on y axis
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
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
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:
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.
So, something like this executed each frame would probably be closer:
Code: Select all
airplaneEntity.AngularVelocity += airplaneEntity.OrientationMatrix.Up * (yawAcceleration * dt);
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.
-
- Posts: 12
- Joined: Sun Nov 03, 2013 9:29 pm
Re: rotate on y axis
Thanks Norbo that worked a treat 
