资源简介
整个Unity项目,使用简单项目展示如何在给定抛物线起点、终点及高度的情况下,运算抛物线抛射力,实现击中目标的最终效果
代码片段和文件信息
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class ShootBall : MonoBehaviour {
public Gameobject BallPrefab;
public Transform HighestPosT;
public Transform StartT;
public Transform AimT;
float jumpgravity;
private void Awake()
{
jumpgravity = Mathf.Abs(Physics.gravity.y);
}
// Update is called once per frame
void Update () {
if(Input.GetKeyDown(KeyCode.Space))
{
Gameobject ball = Instantiate(BallPrefab);
ball.transform.position = StartT.position;
float height1 = HighestPosT.position.y - StartT.position.y;
float height2 = HighestPosT.position.y - AimT.position.y;
float time1 = Mathf.Sqrt(2f * height1 / jumpgravity);
float time = Mathf.Sqrt(2f * height1 / jumpgravity) + Mathf.Sqrt(2f * height2 / jumpgravity);
//Debug.Log(“To Arc “ + time);
Vector3 XZDist = AimT.position - StartT.position;
XZDist.y = 0;
Vector3 vel = XZDist / time;
float t = 0;
Vector3 velvalue = vel + time1 * jumpgravity * Vector3.up;
StartCoroutine(AddForceLater(ball.GetComponent() velvalue));
}
}
IEnumerator AddForceLater(Rigidbody BallRig Vector3 velvalue)
{
yield return new WaitForFixedUpdate();
BallRig.transform.rotation = Quaternion.LookRotation(velvalue);
BallRig.GetComponent().velocity = Vector3.zero;
BallRig.GetComponent().AddForce(velvalue ForceMode.VelocityChange);
}
}
属性 大小 日期 时间 名称
----------- --------- ---------- ----- ----
..A..H. 14336 2019-01-08 11:07 ShootTarget\.vs\ShootTarget\v15\.suo
I.A.... 2054 2019-01-08 10:59 ShootTarget\Assets\Mat\Grey.mat
I.A.... 188 2019-01-08 10:57 ShootTarget\Assets\Mat\Grey.mat.me
I.A.... 2027 2019-01-08 10:57 ShootTarget\Assets\Mat\Red.mat
文件 188 2019-01-08 10:57 ShootTarget\Assets\Mat\Red.mat.me
I.A.... 3099 2019-01-08 11:00 ShootTarget\Assets\Mat\Sphere.prefab
文件 154 2019-01-08 11:00 ShootTarget\Assets\Mat\Sphere.prefab.me
I.A.... 2038 2019-01-08 11:00 ShootTarget\Assets\Mat\Yellow.mat
I.A.... 188 2019-01-08 10:59 ShootTarget\Assets\Mat\Yellow.mat.me
文件 172 2019-01-08 10:57 ShootTarget\Assets\Mat.me
I.A.... 39840 2019-01-08 11:06 ShootTarget\Assets\Scenes\SampleScene.unity
文件 155 2019-01-08 10:54 ShootTarget\Assets\Scenes\SampleScene.unity.me
文件 172 2019-01-08 10:54 ShootTarget\Assets\Scenes.me
文件 1690 2018-12-06 16:02 ShootTarget\Assets\ShootBall.cs
文件 243 2019-01-08 10:59 ShootTarget\Assets\ShootBall.cs.me
文件 377 2018-12-11 00:23 ShootTarget\ProjectSettings\AudioManager.asset
文件 120 2018-12-11 00:23 ShootTarget\ProjectSettings\ClusterInputManager.asset
文件 1105 2018-12-11 00:23 ShootTarget\ProjectSettings\DynamicsManager.asset
文件 268 2018-12-11 00:23 ShootTarget\ProjectSettings\EditorBuildSettings.asset
文件 643 2018-12-11 00:23 ShootTarget\ProjectSettings\EditorSettings.asset
文件 2283 2018-12-11 00:23 ShootTarget\ProjectSettings\GraphicsSettings.asset
文件 6088 2018-12-11 00:23 ShootTarget\ProjectSettings\InputManager.asset
文件 1399 2018-12-11 00:23 ShootTarget\ProjectSettings\NavMeshAreas.asset
文件 159 2018-12-11 00:23 ShootTarget\ProjectSettings\NetworkManager.asset
文件 1469 2018-12-11 00:23 ShootTarget\ProjectSettings\Physics2DSettings.asset
文件 824 2018-12-11 00:23 ShootTarget\ProjectSettings\PresetManager.asset
I.A.... 17619 2019-01-08 10:55 ShootTarget\ProjectSettings\ProjectSettings.asset
文件 28 2019-01-08 10:54 ShootTarget\ProjectSettings\ProjectVersion.txt
文件 5031 2018-12-11 00:23 ShootTarget\ProjectSettings\QualitySettings.asset
文件 435 2018-12-11 00:23 ShootTarget\ProjectSettings\TagManager.asset
............此处省略21个文件信息
- 上一篇:操作系统-银行家算法课设报告及源码
- 下一篇:TSSOP封装尺寸
相关资源
- Simple LOD v1.6
- ProDrawCallOptimizer 4.2
- Rain AI 插件
- unity3d插件-脚本-图像识别OpenCVforUnit
- 5G 物理层概述 R15 3gpp 中文版
- Oculus SDK与Unity版本匹配说明文档
- 5G-NR物理信道与调制
- Unity UGUI自定义树形菜单TreeViewGitHub配
- Unity3D魔女莉莉丝模型.txt
- Unity PrefabEvolution1.3.10
- Unity Shader入门精要最新更正版,含资
- 图像二维傅里叶变换的物理意义
- unity New UI Widgets v1.11.1f1
- EdwinDevelopmentTools
- zCore-5.0.0.unitypackage
- ILRuntime Unity3D程序
- SimpleJSON.unitypackage
- Unity局域网联机插件 Wifi-Hotspot Local
- PageScroll.unitypackage
- Unity_简单2D锁链+锁链延伸detent.unityp
- unity工具IGamesTools批量生成帧动画
- 刀剑音效,unity游戏拔剑、挥剑声音
- Build Report Tool 3.4.11 - 减低游戏使用空
- 原子物理学(第四版)
- BehaviorDesignerTutorials.unitypackage
- Unity3D 餐厅烹饪游戏源码
- esp8266 连接阿里物理网平台远程控制
- Visual Studio 2010 Tools.unitypackage
- 物理作图WORD插件
- Unity开发MMO游戏泰斗破坏神教学视频及
评论
共有 条评论