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

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

问题描述

我想创建什么

  • 将发射导弹对球员,如果有选手发生碰撞的对象,玩家死亡。

问题

  • 如何向玩家导弹的举动。

  • 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天全站免登陆