[英]How to move an object uniformly from one point to another at a fixed angle?
在我的2D Java游戏中,我需要将弹丸从敌人对象直线移动到玩家对象。 我做了一些研究,发现我可以使用Math类的atan2(x,y)方法来获取角度,但是我应该如何在特定角度(方向)上移动弹丸? 任何想法都将非常有帮助。
等速运动方程很简单
positionX = startPositionX + speedX * time
positionY = startPositionX + speedY * time
哪里
speedX = speed * sin(angle)
speedY = speed * cos(angle)
但是大多数游戏都使用渐进方式
posX = posX + speedX / lengthOfTick
posY = posY + speedY / lengthOfTick
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.