Yo guys,
I am working on a basic movement script for a car but i get some problems with my input.
I want a basic force that put my car foward and when i use my horizontal input it move 1 unity to the left to right.
If someone can help me it would be super .
What did i do wrong and how can i do it better in the future.
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class Car_Move : MonoBehaviour {
public float thrust;
public Rigidbody rb;
public float speed;
// Use this for initialization
void Start () {
rb = GetComponent<Rigidbody>();
}
// Update is called once per frame
void FixedUpdate ()
{
Controll ();
rb.AddForce (speed * -6, 0, 0);
}
void Controll (){
if (Input.GetAxis ("Horizontal") > 0) {
rb.AddForce (0, 0, 20f);
Debug.Log ("right");
} else {
if (Input.GetAxis ("Horizontal") > -1) {
rb.AddForce (0, 0, -20f);
Debug.Log ("left");
}
else {
rb.AddForce (speed * -6, 0, 0);
}
}
}
}
Thanks,
Casper