- Home /
Car keeps pulling itself out of the map. Beginner needs help
So my friends and I are making a racing game for a school project. We got it all working except the car. When we drive the car it goes normally, but when it flips it sort of pulls itself towards the bottom of the car. So when the cars bottom is towards the sky or wall, it pulls itself out of the map, or alongside the wall, like spiderman.
here is the script C#: var speed : float = 10.0; var rotationSpeed : float = 100.0; var force = 100;
function Update () {
{rigidbody.AddForce(-transform.up*force);}
if (Input.GetKey(KeyCode.W))
rigidbody.AddForce (transform.forward * 100 * Time.deltaTime);
if (Input.GetKey(KeyCode.S))
rigidbody.AddForce (-(transform.forward) * 4*Time.deltaTime);
if (Input.GetKey(KeyCode.D))
transform.Rotate(0,1.5,0);
if (Input.GetKey(KeyCode.A))
transform.Rotate(0,-1.5,0);
var translation : float = Input.GetAxis ("Vertical") * speed;
var rotation : float = Input.GetAxis ("Horizontal") * rotationSpeed;
translation *= Time.deltaTime;
rotation *= Time.deltaTime;
transform.Translate (0,0, translation);
transform.Rotate (0, rotation, 0);
}
rigidbody.AddForce(-transform.up*force);
is the reason why. -transform.up is relative to the gameobjects local axes.
Try -Vector3.down ins$$anonymous$$d.
That fixed the floating but the car doesn't seem to stay up. Like it flips on it's side all the time
Your answer
Follow this Question
Related Questions
car water floating script help. 2 Answers
Weird Code Error Message 2 Answers
Beginner Car Control Script from FlatTutorials 3 Answers
Driving car FPS 1 Answer