【发布时间】:2018-08-22 00:43:19
【问题描述】:
我对 Unity 和 C# 还很陌生,一直在努力解决这个问题!
我希望我的飞船逐渐加快速度,然后像没有重力一样缓慢停止,因为这将是一场太空游戏!
如果有人可以帮助我,甚至指导我学习这个主题的教程,我将不胜感激! :)
这是我目前宇宙飞船的代码...
using UnityEngine;
using System.Collections;
using UnityStandardAssets.CrossPlatformInput;
public class PlayerMovement : MonoBehaviour {
public float maxSpeed = 6f;
public float rotSpeed = 180f;
void Start ()
{
}
void Update () {
Quaternion rot = transform.rotation;
float z = rot.eulerAngles.z;
z -= CrossPlatformInputManager.GetAxis ("Horizontal") * rotSpeed * Time.deltaTime;
rot = Quaternion.Euler (0, 0, z);
transform.rotation = rot;
Vector3 pos = transform.position;
Vector3 velocity = new Vector3 (0, CrossPlatformInputManager.GetAxis("Vertical") * maxSpeed * Time.deltaTime, 0);
pos += rot * velocity;
transform.position = pos;
}
}
如何做到这一点?
【问题讨论】:
-
所以你想做一些“easeInOutCubic”吗? (取自 CSS)
-
也许this 可以帮助你在不使用物理引擎的情况下实现你想要的(即使我猜在你的情况下使用物理更容易)。