Homing Missiles, How Do They Work?

喜夏-厌秋 提交于 2019-12-02 13:00:36

You can get the distance from one point to another, and turn that into a direction to go to.

//Find the delta time
float delta = (float)gameTime.ElapsedGameTime.TotalSeconds * 60;
//Find the direction
Vector2 direction = mousePosition - misslePosition;
direction.Normalize();
//Move towards it
currentPos += direction * delta;

It needs to be multiplied by the elapsed time so it appears the same no matter what FPS you are running at.

You may need to adjust for speed, but it should create a pattern like this:

If you would like the missle to slowly turn towards the target, you can experiment with MathHelper.Lerp to slowly change the angle.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!