在三维空间中,利用抛物线公式计算弹道,得到一个发射初速度,让导弹打击到指定地点
效果:
脚本使用:只需指定目标点即可
可以通过Hight调整导弹的飞行高度
可以通过Gravity调整导弹的飞行速度
通过以下两个脚本实现。工具脚本计算弹道,Missile脚本每帧更新导弹位置
PhysicsUtil.cs
using UnityEngine;
/// <summary> 物理计算工具
/// <para>ZhangYu 2018-05-10</para>
/// </summary>
public static class PhysicsUtil {
/**findInitialVelocity
* Finds the initial velocity of a projectile given the initial positions and some offsets
* @param Vector3 startPosition - the starting position of the projectile
* @param Vector3 finalPosition - the position that we want to hit
* @param float maxHeightOffset (default=0.6f) - the amount we want to add to the height for short range shots. We need enough clearance so the
* ball will be able to get over the rim before dropping into the target position
* @param float rangeOffset (default=0.11f) - the amount to add to the range to inc