平抛运动

匿名 (未验证) 提交于 2019-12-02 23:38:02

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class PingPaoDemo : MonoBehaviour
{
private float g ; //重力加速度
private float horizontalSpeed; //水平方向速度
private float t; ///时间累积变量

void Start() {     horizontalSpeed = 1;     t = 0;     g =2f; }  // Update is called once per frame void Update() {     t += Time.deltaTime;//时间累积      ///公式:s = 1/2*g*t^2     float s = 0.5f * this.g * t * t; //垂直方向上的移动量     float h = t * horizontalSpeed;  ///水平方向上的移动量      Vector3 vec = new Vector3(0, -s, h);//两个方向上的移动量合一起      this.transform.position += vec; ///把位置增加到原来位置上,改变位置 } 

}

文章来源: https://blog.csdn.net/Hy8636/article/details/90766744
标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!