-SOLVED-Top down movement question (TANK CONTROLS)

Hi,

I have this object with top down movement behavior, the thing is I set up simulated keys “WASD” for W- goes up A- goes right, and such.

The thing is , I actually need " tank controls" like, W goes forward, S goes backwards and A and D should rotate the tank, any of you have tips on how to achieve this?

Thanks!

The top-down behavior doesn’t support relative directions, you’ll have to write the code yourself, it would be something like:

[code]Conditions: Key W is pressed
Actions: Add a force to Tank, angle: Tank.Angle(), length: 200, damping: 0

Conditions: Key S is pressed
Actions: Add a force to Tank, angle: Tank.Angle() + 180, length: 100, damping: 0

Conditions: Key A is pressed
Actions: Rotate Tank at -45 degrees/second

Conditions: Key D is pressed
Actions: Rotate Tank at 45 degrees/second[/code]

Also to make it a bit more realistic and not have it turn when it is not moving at all you should add a condition that when speed (or sum of forces on the tank) is > 5 then do the A and D conditions that Lizard said…

I did what you suggested and the tank moves, but only horizontally.

Take a look at this one, maybe you find the problem through comparison:
Tank.zip (10.4 KB)

1 Like

Ok, this works perfect for the tank, but, My tank is compossed of a tank and a turret that roates following the mouse, so, using this code you sent me the turret moves in the direction of the mouse instead of the direction of the tank I’ll see if I can fix it and report.

UPDATE: I fixed it, simply by applaying the force using the angle of the tank, Thank you so much, this makes it perfect!!!

Or you could do:

Do = Tank.PointX(Turret) ; Tank.PointY(Turret) to the position of Turret

Syncing two objects position using the same force on both is not very robust.