This is my code:
using UnityEngine;
using System.Collections;
public class Movement : MonoBehaviour {
public GameObject player;
public bool down;
public float forward = 15;
public float maxForward = 20;
void Start () {
}
void Update () {
if (Input.GetKeyDown(KeyCode.RightArrow))
down = true;
if (Input.GetKeyUp(KeyCode.RightArrow))
down = false;
if (down == true)
{
player.rigidbody.AddForce(0,0,forward);
}
if (player.rigidbody.velocity.z > maxForward)
{
player.rigidbody.velocity.z = player.rigidbody.velocity.z.normalized;
player.rigidbody.velocity.z *= maxForward;
}
}
}
It does not work lol. Can someone tell me why & tell me how i can make this work? I want to set a maximum speed of a rigidbody sphere. Thanks!