Game Development Community

Lost in Translation between XNA and TorqueX

by Adam Culberson · in Torque X 2D · 12/15/2008 (10:24 pm) · 0 replies

So I'm trying to create a game in TorqueX using TXB and I can't figure out how to make my tank movement the same as I was doing in XNA. In XNA the following solution moves the tank forward and back using the Y axis of the left thumbstick and rotates on the X of the right thumbstick and is very smooth. Here is how I do it in XNA:

playerOneTank.rotation += gamePadState.ThumbSticks.Right.X * 0.1f;

if (gamePadState.ThumbSticks.Left.Y > 0)
{
playerOneTank.velocity = new Vector2((float)Math.Cos(playerOneTank.rotation), (float)Math.Sin(playerOneTank.rotation)) * (gamePadState.ThumbSticks.Left.Y * playerOneTank.speed);
playerOneTank.position += playerOneTank.velocity;
}
if (gamePadState.ThumbSticks.Left.Y < 0)
{
playerOneTank.velocity = new Vector2((float)Math.Cos(playerOneTank.rotation), (float)Math.Sin(playerOneTank.rotation)) * (-gamePadState.ThumbSticks.Left.Y * playerOneTank.speed);
playerOneTank.position -= playerOneTank.velocity;
}

In torqueX, using the default starter game kit and its movement component it wants to do all movement using the Left stick. I changed the mapping so that the X is on the right stick and the Y is on the left stick. Then under ProcessTick I did the following:

if (move != null)
{
_sceneObject.Rotation += move.Sticks[0].X * 5.0f;

if (move.Sticks[0].Y < 0)
{
_sceneObject.Position -= new Vector2((float)Math.Cos(_sceneObject.Rotation), (float)Math.Sin(_sceneObject.Rotation) * (-move.Sticks[0].Y * 2.0f));
}
if (move.Sticks[0].Y > 0)
{
_sceneObject.Position += new Vector2((float)Math.Cos(_sceneObject.Rotation), (float)Math.Sin(_sceneObject.Rotation) * (move.Sticks[0].Y * 2.0f));
}
}

But the tank moves all over the place and does not seem to follow the rotation. Can someone explain to me what is happening with the _sceneObject.Position or _sceneObject.Rotation?

Thank you.

Adam