Unsolved How to change animation movement to face rotation direction?
Constantly_Stuck last edited by
My driving game involves a tank moving forwards and turning when the turn button is pressed.
I am able to make the tank move in the direction it is facing. But if that direction changes whilst the move animation is playing, I don't know how to make the tank movement change dynamically, to keep the movement in line with the direction if is facing.
The solution I currently have is by setting a very short distance for the movement animation, so that at the beginning of each animation it is able to change the direction based on any rotation change.
The problem with this is that by using this method I can only make the movement animation length about 10 pixels - otherwise it produces a distinct sideways motion. And by only moving it 10 pixels, when I want the car to move FAST it means a lot of animations per second... at the high end of speed, this produces a flickering effect in my tank.
I'm sure there must be a better way of doing this... can anyone help please? I've copied a sample of my code below to illustrate how I'm currently doing it.
to: rotation + 360
to: y + ((tank.direction * pixelTravel) * Math.sin(tank.rotation * (Math.PI / 180)))
to: x + ((tank.direction * pixelTravel) * Math.cos(tank.rotation * (Math.PI /180)))