I’m trying to limit my characters speed but nothing I try works. Here’s my current code:
#pragma strict
var force : Vector2;
var bike : Transform;
var power : int;
var brake : int;
var maxForward : int;
var trigfunction : Vector3;
function Update () {
trigfunction = bike.TransformDirection(Vector3.right);
force.Set(trigfunction.x,trigfunction.y);
if (GetComponent.<Rigidbody2D>().velocity.magnitude < maxForward)
GetComponent.<Rigidbody2D>().AddForce(force);
if (Input.GetKey(KeyCode.UpArrow))
GetComponent.<Rigidbody2D>().AddForce(force*power);
if (Input.GetKey(KeyCode.DownArrow))
GetComponent.<Rigidbody2D>().AddForce(force*brake*-1);
}
What’s wrong?