Monday, 11 July 2011

Assignment_Progress

The next thing that I had to do was to apply a movement script to the car. Here is an example of the scene that my group member Wei Jie had done.




.

My Job was to add a movement script to the orange colored car so that it would be able to move up and down, left and right. Below is an example of the movement script.


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.