Move model forward base on model orientation
Posted
by
ChocoMan
on Game Development
See other posts from Game Development
or by ChocoMan
Published on 2012-09-08T05:54:42Z
Indexed on
2012/09/08
9:51 UTC
Read the original article
Hit count: 363
My model rotates on it's own Y-axis regardless of where it is in the world. Here are the controls for the left ThumbStick:
UP (move model forward on Z-Axis) DOWN (move model backward on Z-Axis) LEFT & RIGHT (strafe to either side)
The problem is adjusting the direction the model's orientation UP and DOWN if the player should also rotate the player while moving forward or backwards.
An example what Im trying to achieve would be a car doing donuts. The car is always facing the current direction that it interprets as forward (or rear as backwards) in relation to it's local rotation.
Here is how Im calling the movement:
// Rotate model with Right Thumbstick along X-Axis
modelRotation -= pController.ThumbSticks.Right.X * mRotSpeed;
// Move Forward
if (pController.IsButtonDown(Buttons.LeftThumbstickUp))
{
modelPosition.Z -= -pController.ThumbSticks.Left.Y * speed;
}
// Move Backward
if (pController.IsButtonDown(Buttons.LeftThumbstickDown))
{
modelPosition.Z += pController.ThumbSticks.Left.Y * speed;
}
// Strafe Left
if (pController.IsButtonDown(Buttons.LeftThumbstickLeft))
{
modelPosition.X += -pController.ThumbSticks.Left.X * speed;
}
// Strafe Right
if (pController.IsButtonDown(Buttons.LeftThumbstickRight))
{
modelPosition.X -= pController.ThumbSticks.Left.X * speed;
}
// DeadZone
if (!pController.IsButtonDown(Buttons.LeftThumbstickUp) &&
!pController.IsButtonDown(Buttons.LeftThumbstickDown) &&
!pController.IsButtonDown(Buttons.LeftThumbstickLeft) &&
!pController.IsButtonDown(Buttons.LeftThumbstickRight))
{
}
© Game Development or respective owner