Bellow is the CS script:
//using UnityEngine;
//using System.Collections;
//
using UnityEngine;
using System.Collections;
// Class: Movement
// Description: Controller how the players ship navigates
// around the scene
public class Movement : MonoBehaviour {
Rigidbody _rbody; // for the physical properties and behaviours
Vector3 m_Position = new Vector3(0.0f, 0.0f, 0.0f); // keep track of the position in the world
Vector3 m_TransFroce = new Vector3(0.0f, 0.0f, 0.0f); // the translation force variable
Vector3 m_RotForce = new Vector3(0.0f, 0.0f, 0.0f ); // the rotation force variable
float Pitch = 0.0f; // Pitch rotation value
float Yaw = 0.0f; // Yaw rotation value
float Roll = 0.0f; // Roll rotation value
float AmbientSpeed = 200.0f; // translation speed
float RotationSpeed = 20.0f; // rotation speed
Quaternion PrevRotation = Quaternion.identity; // keep track of the previous rotation
Quaternion CurRotation = Quaternion.identity; // the currently applied rotation
void Start()
{
_rbody = gameObject.GetComponent<Rigidbody>();
}
void FixedUpdate ()
{
ControlRotation();
ControlMotion ();
transform.RotateAroundLocal(Vector3.up, m_RotForce.y);
transform.RotateAroundLocal( transform.forward, Roll);
transform.Translate((m_Position+m_TransFroce));
}
void ControlMotion(){
// Levitation
if(Input.GetKey("c")){
m_TransFroce.y += 2.0f * Time.deltaTime;
if( m_TransFroce.y > 3.0f )
m_TransFroce.y = 3.0f;
}else if(Input.GetKey("v")){
m_TransFroce.y -= 2.0f * Time.deltaTime;
}
if(Input.GetKey("w")){
m_TransFroce.z += 2.0f * Time.deltaTime;
if( m_TransFroce.z > 3.0f )
m_TransFroce.z = 3.0f;
}else if(Input.GetKey("s")){
m_TransFroce.z -= 2.0f * Time.deltaTime;
if( m_TransFroce.z < -3.0f )
m_TransFroce.z = -3.0f;
}
}
void ControlRotation(){
if(Input.GetKey("a"))
{
m_RotForce.y -= 2.0f * Time.deltaTime;
Roll -= 2.0f * Time.deltaTime;
Roll = Mathf.Clamp(Roll, -20, 20);
if( m_RotForce.y < -3.0f )
m_RotForce.y = -3.0f;
}
else if(Input.GetKey("d")) {
m_RotForce.y += 2.0f * Time.deltaTime;
Roll += 2.0f * Time.deltaTime;
Roll = Mathf.Clamp(Roll, -20, 20);
if( m_RotForce.y > 3.0f )
m_RotForce.y = 3.0f;
if( Roll != 0.0f )
Roll -= Roll * Time.deltaTime;
}
else{
if( m_RotForce.y != 0.0f ){
m_RotForce += -m_RotForce * Time.deltaTime;
}
if( Roll != 0 )
Roll += -Roll * Time.deltaTime;
}
}
};
Please Advise

New Topic/Question
Reply




MultiQuote




|