So the problem is basicly that my player moves back to the middle lane instantly without a button being pressed which would make it do that. So when I make the player go left, it instantly goes back to the middle like the following video shows, why???
The script:
#pragma strict
var left = false;
var mid = false;
var right = false;
function FixedUpdate ()
{
GetComponent.<Rigidbody>().AddForce (Vector3.down * 35);
GetComponent.<Rigidbody>().AddForce (Vector3.forward * 5);
// if (Input.GetKey (KeyCode.W))
// {
// GetComponent.<Rigidbody>().AddForce (Vector3.forward * 110);
// }
// if (Input.GetKey (KeyCode.S))
// {
// GetComponent.<Rigidbody>().AddForce (Vector3.back * 80);
// }
if (Input.GetKey (KeyCode.A) && mid == true || right == true)
{
transform.Translate (Vector3.left * Time.deltaTime * 210);
}
if (Input.GetKey (KeyCode.D) && mid == true || left == true)
{
transform.Translate (Vector3.right * Time.deltaTime * 210);
}
{
GetComponent.<Rigidbody>().velocity = Vector3.ClampMagnitude(GetComponent.<Rigidbody>().velocity, maxVel);
}
}
var maxVel : float = 16.0;
function OnCollisionEnter (hit : Collision)
{
if(hit.gameObject.name == "Left")
{
left = true;
mid = false;
right = false;
}
if(hit.gameObject.name == "Mid")
{
left = false;
mid = true;
right = false;
}
if(hit.gameObject.name == "Right")
{
left = false;
mid = false;
right = true;
}
}
//function OnCollisionExit (hit : Collision)
//{
// if(hit.gameObject.name == "Floor")
// {
// yield WaitForSeconds(0.15);
// }
//}