寻的导弹,它们是如何工作的? [英] Homing Missiles, How Do They Work?

查看:28
本文介绍了寻的导弹,它们是如何工作的?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试创建的内容

  • 一个会向玩家发射导弹的物体,如果它与玩家相撞,玩家就会死亡.

问题

  • 导弹如何朝玩家移动.

  • How does the missile move towards the player.

如何让导弹移动,使其不会立即直接朝玩家移动(以一个角度缓慢移动).

How do I make the missile move so that it does not instantly move directly towards the player(to slowly move on an angle).

我有一个公式,让鼠标成为玩家",而导弹则指向它.

I have a formula for the mouse to be the "Player" and the missile to go towards it.

        mouse = Mouse.GetState();

        mousePosition = new Vector2(mouse.X, mouse.Y);

        A = (mouse.X - Position.X);
        B = (mouse.Y - Position.Y);
        C = (A * A) + (B * B);

        C = (float)Math.Sqrt(C);

        Angle1 = A / C;
        Angle2 = B / C;

(画画最好!)

这只能得到导弹到玩家的距离,现在我需要找到移动导弹的角度或其他东西,我需要做什么?

This only gets the distance from missile to player, now I need to find the angle or something to move the missile, what do I need to do?

推荐答案

你可以得到一个点到另一个点的距离,然后把它变成一个要去的方向.

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;

它需要乘以经过的时间,因此无论您以何种 FPS 运行,它看起来都是一样的.

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:

如果你想让导弹慢慢转向目标,你可以尝试使用MathHelper.Lerp来慢慢改变角度.

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

这篇关于寻的导弹,它们是如何工作的?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆