I am trying to make an object move forwards, so I used this bit of code:
rigidbody.AddForce(Vector3.forward * speed, ForceMode.Force);
But it will only move in the Z direction. I read online that Vector3.forward is just shorthand for the Z axis so that makes sense, but is there a way of moving in the actual forward direction? Also I have one more question/bug, after it moves a ways it will start going really slowly, even when the speed is supposedly still at a high number.
Here is the whole script:
#pragma strict
var speed : float;
var maxSpeed : float;
var acceleration : float;
function Start () {
}
function Update () {
}
function FixedUpdate(){
if(Input.GetKey("w")){
if(speed < maxSpeed){
speed += acceleration;
rigidbody.AddForce(Vector3.forward * speed, ForceMode.Force);
}
}
if(Input.GetKey("a")){
transform.Rotate(-Vector3(0, 1, 0));
}
if(Input.GetKey("d")){
transform.Rotate(Vector3(0, 1, 0));
}
}