Skip to content

Instantly share code, notes, and snippets.

@N-Carter
Created May 5, 2011 22:36
Show Gist options
  • Save N-Carter/958119 to your computer and use it in GitHub Desktop.
Save N-Carter/958119 to your computer and use it in GitHub Desktop.
Simple ship controls
protected override void FixedUpdate()
{
if(m_Controls != null)
{
float turnFactor = Mathf.Lerp(1.0f, 0.5f, m_Controls.thrust);
rigidbody.AddRelativeTorque(Vector3.right * m_Controls.pitch * m_PitchFactor * turnFactor);
rigidbody.AddRelativeTorque(Vector3.forward * m_Controls.roll * m_RollFactor * turnFactor);
rigidbody.AddRelativeTorque(Vector3.up * m_Controls.yaw * m_YawFactor * turnFactor);
m_ThrustAxis.current = m_Controls.thrust;
m_ThrustAxis.Update();
rigidbody.AddRelativeForce(Vector3.forward * (m_ThrustAxis.current * m_ThrustFactor + m_BaseThrust));
Fire(0, m_Controls.primaryFire);
Fire(1, m_Controls.secondaryFire);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment