3D游戏HW2
简答并用程序验证
游戏对象运动的本质是什么?
游戏对象运动的本质是游戏对象每一帧在空间上的变化,例如位置发生变化(Position),或者发生了旋转(Rotation)。
请用三种方法以上方法,实现物体的抛物线运动。
- 新建一个Vector3变量,为change,水平方向上的变化每一帧都是固定的,水平速度 * 时间间隔,竖直方向上为竖直速度 * 时间间隔,z方向为0。
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class Behavior : MonoBehaviour {
// Use this for initialization
void Start () {
}
private float verticalSpeed = 0.00f;
public float horizontalSpeed = 5.00f;
const float g = 0.098f;
// Update is called once per frame
void Update () {
Vector3 change = new Vector3 (Time.deltaTime * horizontalSpeed, -Time.deltaTime * verticalSpeed, 0.0f);
this.transform.position += change;
verticalSpeed += g;
}
}
- 与1类似,但是不调用position,而是调用Translate函数
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class Behavior : MonoBehaviour {
// Use this for initialization
void Start () {
}
private float verticalSpeed = 0.00f;
public float horizontalSpeed = 5.00f;
const float g = 0.098f;
// Update is called once per frame
void Update () {
Vector3 change = new Vector3 (Time.deltaTime * horizontalSpeed, -Time.deltaTime * verticalSpeed, 0.0f);
this.transform.Translate (change);
verticalSpeed += g;
}
}
- 直接运用position的加减来完成
using Syst