Unity C# 计算导弹抛物线弹道和转向

本文介绍如何在Unity中使用C#计算导弹的抛物线弹道并实现动态转向。通过设置发射初速度和调整高度、重力参数,导弹能够精准打击到目标点。内容包括两个关键脚本:PhysicsUtil.cs用于计算弹道,Missile.cs负责导弹位置的每帧更新。
摘要由CSDN通过智能技术生成

在三维空间中,利用抛物线公式计算弹道,得到一个发射初速度,让导弹打击到指定地点
效果:
弹道效果

脚本属性
脚本使用:只需指定目标点即可
可以通过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
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值