首页 > 解决方案 > How to find how far to rotate with position?

问题描述

Let's say I had my player at position 1, and my enemy at position 2. What would I need to do with the two points's positions to get the rotation needed for the player to look at the enemy, assuming that the player starts at zero degrees?

标签: mathrotation

解决方案


x1 = player's X coordinate
y1 = player's Y coordinate

x2 = enemy's X coordinate
y2 = enemy's Y coordinate

angle = math.atan2(y2 - y1, x2 - x1) * 180 / math.pi()

from there, you can get the angle you needed to turn : )


推荐阅读