.
using UnityEngine;
using System.Collections;
public class carMove : MonoBehaviour
{
#region variables
public float bikespeed = 100;
public float turnspeed = 1;
#endregion
void Update()
{
// this moves the car forward
if (Input.GetKey("up"))
{
this.rigidbody.AddForce(transform.up * bikespeed);
}
// this moves the car backward
if (Input.GetKey("down"))
{
this.rigidbody.AddForce(transform.up * -bikespeed);
}
// this moves the car up
if (Input.GetKey("Space"))
{
this.rigidbody.AddForce(transform.forward * -bikespeed);
}
//this rotates the car sideways
Vector3 rotation = this.transform.localEulerAngles;
rotation.y = rotation.y + Input.GetAxis("Horizontal") * turnspeed;
this.transform.localEulerAngles = rotation;
}
}
I needed to do some editing to the script, but the idea is there. I just need to make sure that the formal movements are there before I do the complicated steps, such as adding a boundary for how much the car can slide about a particular area.
Now, I have to add the movement script to the car object. Since, Wei Jie has done the movement of the road and environment, I need to make sure I get the movement of the car in a logical manner.
This shows the car turning as it moves along the track.
The car jumps as it moves to avoid obstacles.
The car can move forward and backwards.



