-=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- (c) WidthPadding Industries 1987 0|538|0 -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=-
SoCoder -> Snippet Home -> AI and Movement


 
Pakz
Created : 27 October 2019
 
Language : Monkey2

Shortest turn angle vs target angle

Get distance between angle and target angle. (turrets/homing missiles)

Latest Update

A couple of years ago I used a for loop and counted how many steps were in a turn to the left side or right side towards the target angle. I now found some code that returns the distance between a angle and target angle.

The function in the code returns a negative float value if the turn to the left is closer and positive if the turn to the right is closer. The value is the actual angle difference.

I have already used this function in a game where it is used to rotate homing missiles towards the player.

The version here is in monkey2 code and it uses radians. To convert to the other angle version you would need to change the Pi and TwoPi inside the function to degrees. this is *180/Pi I think it was? You might need to look that up.

 

Comments


Monday, 28 October 2019, 17:13
Jayenkai
A handy function to have, and useful in other scenarios, too.
Eg, ships battling each other, whilst screen-wrapping is in effect, so the enemy knows the shortest distance including taking a shortcut.