【问题标题】:How to make homing missiles(auto aim target)?如何制作寻的导弹(自动瞄准目标)?
【发布时间】:2015-04-04 06:44:00
【问题描述】:

我有一个 2d 游戏,我想要一个导弹瞄准一个目标,但首先我想设置它的轨迹一些 coll stuff 湖桶滚动。 我找不到(除了统一资产,我不想付钱)如何制作它,我的意思是如何瞄准和如何设置轨迹。 即使只是瞄准帮助也可以, 提前致谢!

【问题讨论】:

    标签: c# unity3d 2d


    【解决方案1】:

    如果您想让炮塔瞄准目标,只需执行 transform.LookAt(Target.position)。您可以使用转向行为来定位导弹。基本上,它将校准到达到目标所需的速度。 这是一个例子:

    //First we get the direction we need to travel in
    Vector2 direction = (Target.position - transform.position).normalized;
    
    //Multiply it by the maximum speed we're trying to reach
    Vector2 desiredVelocity = direction * MaxSpeed;
    
    //Subtract the current velocity. This is the calibration force
    Vector2 steeringForce = desiredVelocity - rigidbody2D.Velocity;
    
    //Apply the steering. The less the mass, the more effective the steering
    rigidbody2D.ApplyForce(steering);
    

    滚桶可以与转向/归位分开进行。只需在 Z 轴上旋转即可。如果你说的是绕圈旋转……那就更复杂了。您可能只想跳过它或使用动画对其进行硬编码。

    【讨论】:

    • 他说 2d。使用Vector2rigidbody2d
    • 糟糕,很抱歉。更改了代码并添加了一些说明。
    • :-)​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-04-20
    • 1970-01-01
    • 2015-06-23
    • 1970-01-01
    • 2016-07-17
    • 1970-01-01
    相关资源
    最近更新 更多