beanhorstmann
beanhorstmann

Reputation: 279

How to move 3D model on XNA?

I want to control my 3D model, move it every direction but I don't know way to do this. Anybody have any idea ?

Upvotes: 0

Views: 2060

Answers (1)

Blau
Blau

Reputation: 5762

You only have to provide to the effect the model's world transform.

 Matrix World = Matrix.CreateWorld(position, forward, up);

In your update method you can modify the position:

  LastPosition = Position;  

  if (IsKeyDonw(Left)  Position -= Vector3.UnitX * Speed * ElapsedTime; ForwardDirty = true;     
  if (IsKeyDonw(Right)  Position += Vector3.UnitX * Speed * ElapsedTime; ForwardDirty = true;     
  if (IsKeyDonw(Up)  Position -= Vector3.UnitZ * Speed * ElapsedTime;  ForwardDirty = true;     
  if (IsKeyDonw(Down)  Position += Vector3.UnitZ * Speed * ElapsedTime; ForwardDirty = true;     


// the forward is the direction where will point your model.

if (ForwardDirty) {
     Forward = Position - LastPosition;
     Forward.Normalize();
     ForwardDirty = false;
}

You also can base your movement in forward vector, or smooth the angle change interpolating the final forward with the current,...

Upvotes: 1

Related Questions