Hey everybody,
I’m quite new to programming and Unity. I’m making a race game for a project at school and I got stuck at this piece of code:
var speed = 0.1;
var rotateSpeed = 50.0;
var baseSpeed = 1.0;
function Update () {
var y = Input.GetAxis(“Horizontal”) * Time.deltaTime * rotateSpeed;
var z = baseSpeed + Input.GetAxis(“Vertical”) * Time.deltaTime * speed;
if (z <= baseSpeed)
{
z=baseSpeed;
}
var hitInfo : RaycastHit;
if ( Physics.Raycast( transform.position - transform.up, -transform.up, hitInfo, 1 ) z >= 0.1 )
{
transform.position = hitInfo.point + transform.up;
//hitInfo.normal = ; }
transform.Translate(0, 0, z);
transform.Rotate(0, y, 0);
}
The bold part is the part I have a question about. I need to get this fixed so that the rotation of my character is the same as the normal (which is the track he collides with).
How do I do that?
Thanks in advance.