- Home /
Vehicle Movement Script Not Moving Forwards
My vehicle script rotates but doesn't move forwards. Whats the problem with my code? EDIT Still doesent work after removing spaces from name. What could i add to make it work?
var car : Transform;
var speed : float = 1.0;
var rotateSpeed : float = 3.0;
function Start() {
car.GetComponent("Drive Script").enabled = false;
}
function Update() {
if(Input.GetKeyDown("t"))
{
car.GetComponent("Drive Script").enabled = false;
}
if(Input.GetButtonDown("Action"))
{
car.GetComponent("Drive Script").enabled = true;
}
var controller : CharacterController = GetComponent(CharacterController);
transform.Rotate(0, Input.GetAxis ("Horizontal") * rotateSpeed, 0);
if (controller.isGrounded) {
// We are grounded, so recalculate
// move direction directly from axes
moveDirection = Vector3(0, 0,
Input.GetAxis("Vertical"));
moveDirection = transform.TransformDirection(moveDirection);
moveDirection * speed;
}
}
Answer by Montraydavis · Oct 14, 2012 at 01:20 PM
Well for one, you can NOT have spaces in your Script names . . . Fix that, and see if it is then working .
car.GetComponent("Drive Script").enabled = true; // Your car is never enabled because "Drive Script" is invalid .
Your answer
Follow this Question
Related Questions
Can I change movement from Unity 3d into Unity 3D iOS 2 Answers
how to make my character wall jump(run) 0 Answers
How do I stop my character from sliding after adding force? 0 Answers
Issues with camera and player rotation scripts for basic FPS controller. 2 Answers
Movement FPS Independent, how to? 1 Answer