# How to make turning angle negative if target position to the left of the vehicle

I probably worded the title very poorly, so I apologize if it has caused any confusion.

I am attempting to get the angle needed to turn wheels in order to point them towards a target position.
Using the following code, I’ve managed to do just that as long as the target position is to the right of the wheels.

``````local direction = Position - car.CarBody.Position
local angle = math.deg(math.atan2(direction.x, direction.z) + math.pi)
``````

However, if the target position is to the left of the vehicle it still calculates the angle needed, but instead of the angle being negative it is still positive. Therefore, if the target position is to the left of the wheels then they turn the correct amount, but to the right.

For example, in the following gif the green part is the target position for the wheels to turn towards. They turn the correct amount, but in the wrong direction.
https://gyazo.com/974cf25e4fc161aac8663ffd765a8571

Basically, how can I tell if the target position is to the left of the wheels? If I can detect that, I can easily just make the angle negative.
(sorry if it is simple math, my brain isn’t working with me today)

Nevermind! Turns out it was just turning the opposite direction the whole time. Just had to multiply the angle by -1, and it works fine now.

1 Like