math - 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?
解决方案
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 : )
推荐阅读
- elasticsearch - 在 Elasticsearch 中使用 SearchTemplate 和 Should 子句进行日期范围查询
- tfs - TFS 查询 - 缺少子链接的父级
- angular - 如何覆盖现有管道
- javascript - 使用 Sikuli 检查应用程序是否已打开
- babeljs - 通过 babel 删除单个评论
- linux - 在 Internet 存档上重定向后获取 URL
- postgresql - 将用户添加到他们不属于的项目?Postgres / Vue JS
- css - 在 Wordpress/Primer/Mins/Elementor 网站中使用 CSS 制作标题全宽
- python - 在 django 中,Middleware 两次触发错误
- android - 在一个构建配置上生成签名的 APK 失败