How to make an object turn in the direction it 's moving?

Hi! I’m currently trying to make a Unity game involving a tank, and when you move left for example, I want the whole chassis to turn to face the new direction (like a real tank). However, I have not been able to do this, though I have tried. I am looking for any help.

Thanks!

SEND MOAR TANKS!!!

Seriously… what you need is to turn the X/Y moves into an angle heading.

Sine/Cosine/Atan2 (sin/cos/atan2) and rotational familiarity and conventions

https://discussions.unity.com/t/863372/8

Using Mathf.Atan2() to derive heading:

https://discussions.unity.com/t/769743/4

Or if you prefer, have a working twinstick tank!!

https://github.com/kurtdekker/proximity_buttons/blob/master/proximity_buttons/Assets/DemoTwinStickTanker/TwinStickTankController.cs

Supports backing up too, just set the boolean in the controller.

8955804--1229874--Screen Shot 2023-04-17 at 7.09.37 PM.png

Full project all set up in the above repository.

proximity_buttons is presently hosted at these locations:

https://bitbucket.org/kurtdekker/proximity_buttons

https://github.com/kurtdekker/proximity_buttons

https://gitlab.com/kurtdekker/proximity_buttons

https://sourceforge.net/projects/proximity-buttons/