I have followed the tut for this ShipController, but still my ship aint moving.
I have set up the “Thrust” on E and Q.
please why aint my ship moving in any direction?
CODE:
using UnityEngine;
using System.Collections;
public class ShipController : MonoBehaviour {
public float maxTurnRate = 1200f;
public Vector3 maxImpulse = new Vector3 (10f, 10f, 700f);
public Vector3 velocity = Vector3.zero;
public float impulseSensitivity = 500f;
public float turnSensitivity = 1200f;
private Vector3 impulse = Vector3.zero;
private float desiredImpulse = 0f;
private Vector3 impulseActual = Vector3.zero;
private float maxImpulseChange = 100f;
private Vector3 turnRate = Vector3.zero;
private float desiredImpulseInput = 0f;
private float desiredTurnXInput = 0f;
private float desiredTurnYInput = 0f;
private float desiredInputX = 0f;
private float desiredInputY = 0f;
private float desiredTurnX = 0f;
private float desiredTurnY = 0f;
private Transform thisTransform;
public float enginePowerValue = 0f;
public GUIText enginePercentText;
public Vector3 Velocity {
get
{
return Velocity;
}
}
public Vector3 Impulse {
get
{
return impulse;
}
set
{
impulse.x = Mathf.Clamp (value.x, 0, maxImpulse.x);
impulse.x = Mathf.Clamp (value.y, 0, maxImpulse.y);
impulse.x = Mathf.Clamp (value.z, 0, maxImpulse.z);
}
}
// Use this for initialization
void Start () {
thisTransform = transform;
}
void OnEnginePowerChange (){
if(enginePercentText != null)
{
enginePowerValue = (desiredImpulse / maxImpulse.z * 100) / 100f;
enginePercentText.text = "Engine" + " " + (enginePowerValue * 100).ToString ("f0") + "%";
}
}
// Update is called once per frame
void Update () {
OnEnginePowerChange();
thisTransform.Rotate (turnRate * Time.deltaTime, Space.Self);
if(Vector3.Distance (impulse, impulseActual) < maxImpulseChange * Time.deltaTime)
{
impulseActual = impulse;
}
else
{
impulseActual += (impulse - impulseActual).normalized * maxImpulseChange * Time.deltaTime;
}
velocity = thisTransform.rotation * impulseActual / 10f;
thisTransform.Translate (velocity * Time.deltaTime, Space.World);
}
void CheckInput()
{
if(this == null)
{
return;
}
desiredImpulseInput = 0f;
desiredTurnXInput = 0f;
desiredTurnYInput = 0f;
desiredInputX = 0f;
desiredInputY = 0f;
desiredImpulseInput += Input.GetAxis ("Thrust") * impulseSensitivity * Time.deltaTime;
desiredImpulse = (Mathf.Clamp (desiredImpulseInput, GetImpulse2(), GetMaxImpulse2()));
desiredImpulse += desiredImpulseInput;
desiredTurnXInput += Input.GetAxis ("Vertical") * turnSensitivity * Time.deltaTime;
desiredTurnX = (Mathf.Clamp(desiredTurnXInput, -GetMaxTurnRate(), GetMaxTurnRate()));
desiredTurnX += desiredTurnXInput;
desiredTurnYInput += Input.GetAxis ("Horizontal") * turnSensitivity * Time.deltaTime;
desiredTurnY = (Mathf.Clamp(desiredTurnYInput, -GetMaxTurnRate(), GetMaxTurnRate()));
desiredTurnY += desiredTurnYInput;
SetImpulse2(desiredImpulse);
SetTurnRate(desiredTurnX, desiredTurnY, 0);
}
public void SetImpulse2(float z)
{
Impulse = new Vector3(0,0,z);
}
public float GetImpulse2()
{
return impulse.z;
}
public float GetMaxImpulse2()
{
return maxImpulse.z;
}
public void SetTurnRate (float x, float y, float z)
{
turnRate.x = Mathf.Clamp (x, -maxTurnRate, maxTurnRate);
turnRate.y = Mathf.Clamp (y, -maxTurnRate, maxTurnRate);
turnRate.z = Mathf.Clamp (z, -maxTurnRate, maxTurnRate);
}
public void SetTurnRate (Vector3 v)
{
SetTurnRate (v.x, v.y, v.z);
}
public Vector3 GetTurnRate()
{
return turnRate;
}
public float GetMaxTurnRate()
{
return maxTurnRate;
}
}