我想添加一個現實的前瞻性駕駛行爲,以簡單的車輛。目前我使用的是剛體MovePosition,當我從Input中檢測到正向/反向軸時,我只應用MoveRotation。車輛的現實轉彎
相反,我想要應用方向/旋轉,即使汽車正在滑行,但不希望它在靜止時轉向,就好像它是一輛履帶式車輛。我還希望轉彎似乎來自車輛前方,車輪(不是遊戲中的實際物體)將位於該前方。
我迄今主要是從坦克教程借:
m_MovementInputValue = Input.GetAxis(m_MovementAxisName);
m_TurnInputValue = Input.GetAxis(m_TurnAxisName);
// Create a vector in the direction the tank is facing with a magnitude based on the input, speed and the time between frames.
Vector3 movement = transform.forward * m_MovementInputValue * m_Speed * Time.deltaTime;
// Apply this movement to the rigidbody's position.
m_Rigidbody.MovePosition(m_Rigidbody.position + movement);
if (m_MovementInputValue > 0)
{
float turn = m_TurnInputValue * m_TurnSpeed * Time.deltaTime;
// Make this into a rotation in the y axis.
Quaternion turnRotation = Quaternion.Euler(0f, turn, 0f);
// Apply this rotation to the rigidbody's rotation.
m_Rigidbody.MoveRotation(m_Rigidbody.rotation * turnRotation);
}
我玩輪撞機,但它比我所尋找的更復雜。我可以再試一次 至於其餘的,謝謝。我唯一沒有得到的是velocity.forward。是否在Unity 5中被棄用? – Roger
對不起,我在說速度矢量的前向分量,但它沒有太大意義。幅度/ maxSpeed似乎更合適,我會更新我的帖子。 – Sharundaar