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; ///把位置增加到原来位置上,改变位置
}
}