Hello guys. Im trying to make a tank move in angles in my screen.
Im forgot the math to do it.
The tank can rotate in the origin and by pressing W or S , the tank should go forward to that direction or backwards.
Help
public void update() {
float x = getX();
float y = getY();
float a = 1;
float b = 1;
//Sprite.getRotation return : the rotation of the sprite in degrees
a = sprite.getRotation() * MathUtils.degreesToRadians;
b = y - x * a;
//y = arctan * x + b
if (pressingRight) {
sprite.rotate(-5);
}
if (pressingLeft) {
sprite.rotate(5);
}
if (pressingUp) {
sprite.setX(x + 3);
sprite.setY(a * (getX() + 3) + b);
}
if (pressingDown) {
sprite.setX(x - 3);
sprite.setY(a * (getX() - 3) + b);
}
}