Moving 3d model in the direction it's faces

I relized a simple movement

public void Update(GameTime gameTime)
{
if (Keyboard.GetState().IsKeyDown(Keys.Left))
{
ACamera.AWorldMatrix *= Matrix.CreateTranslation(.1f, 0, 0);
}
if (Keyboard.GetState().IsKeyDown(Keys.Right))
{
ACamera.AWorldMatrix *= Matrix.CreateTranslation(-.1f, 0, 0);
}
if (Keyboard.GetState().IsKeyDown(Keys.Up))
{
ACamera.AWorldMatrix *= Matrix.CreateTranslation(0, -.1f, 0);
}
if (Keyboard.GetState().IsKeyDown(Keys.Down))
{
ACamera.AWorldMatrix *= Matrix.CreateTranslation(0, .1f, 0);
}
}

What is the question? :wink:

:joy::joy::joy:
I want my character to turn while walking.
UP key - start of movement
RIGHT and LEFT - turn to change direction
DOWN key - a full 180 degree turn relative to the direction in which it moved

I tried to add for turning
ACamera.AWorldMatrix *=Matrix.CreateRotationZ(0.001f) * Matrix.CreateTranslation(.1f, 0, 0);
but it just starts spinning around the center of the coordinate axes.

You should store the amount of translation and rotation between frames, then create the world with: Scale * Rotation * Translation, not multiply the world again by the updated world. (At least it is what do)

1 Like