My goal is to create a frame independent vehicle controller script that will turn/rotate and thrust my motor boat forward and backward.
My current code produces movement in rotation super slow and very piddly values (decimals). When the vertical axis is 1 I want the vehicle to increase velocity by 10(acceleration) all the way up to 40(maxVelocity).
Where am I going wrong?
public float maxVelocity = 40f;
public float acceleration = 10f;
public float turnAcceleration = 5f;
// Update is called once per frame
void Update () {
float moveInputAmount = Input.GetAxis ("Vertical");
float turnInputAmount = Input.GetAxis ("Horizontal");
// Rotation/Turning
// Apply turn
Vector3 turnForce = Vector3.up * turnInputAmount * this.turnAcceleration * Time.deltaTime;
rigidbody.AddRelativeTorque(turnForce);
// Moving forward backward
// Throttle the boat to the max velocity in both positive and negative direction
Vector3 thrustForce = Vector3.forward * moveInputAmount * this.acceleration * Time.deltaTime;
if(rigidbody.velocity.z < this.maxVelocity && rigidbody.velocity.z > -this.maxVelocity)
{
rigidbody.AddRelativeForce(thrustForce);
}
Debug.Log (thrustForce + " ~ " + turnForce);
Debug.Log ("Boat Velocity: " + rigidbody.velocity);
Debug.Log ("Boat Rotation: " + rigidbody.rotation);
}