Thursday, 11 August 2011

Assignment Final


I have finished checking the game for any flaws. The controls are working fine. I helped with the creation of the controls and contributed to the overall design of the game.

This was the final script for the movement of the car:


public class PlayerControl : MonoBehaviour
{
    public float playerSpeed = 100;
    public float bankSpeed = 0.2f;
public float speed = 10.0f;
public float jumpForce = 10.0f;
public float gravityForce = 20.0f;
    public int bankAngle = 70;
    public CharacterController controller;

(These are the functions defined at the top. Each have a subsequent value due to the valuables below)


private Vector3 dir;
    private Vector3 moveDirection = Vector3.zero;
    private float expSpeed;
    //public static float pSpeed;

    // Use this for initialization
    void Start()
    {
       //publish playerSpeed via pSpeed
       //pSpeed = playerSpeed;

       // this.expSpeed = this.playerSpeed;
    }

    // Update is called once per frame
    void Update()
    {
        #region Move the player
        //Get the  left and right arrow keys to control the x direction of player
        float horMov = Input.GetAxis("Horizontal") * playerSpeed * Time.deltaTime;

(This tells the program to use the left and right keys and control the movement of the car in the X direction)

        // Get the up and down arrow keys to control the y direction of player
        float verMov = Input.GetAxis("Vertical") * playerSpeed * Time.deltaTime;

(This tells the program to use the left and right keys and control the movement of the car in the Y direction)

        //exponitially increase speed
        this.expSpeed = (this.expSpeed * 1.01f);

(This increases the speed of the car linearly per second)

        // move the player left and right
        transform.Translate(Vector3.right * (horMov+expSpeed));

        //move the forward and backward
        transform.Translate(Vector3.back * -verMov);

(This moves the car left and right)
        #endregion
//clamp the player movement
this.transform.position = new Vector3(Mathf.Clamp(this.transform.position.x, -30f, 50f),
                                     this.transform.position.y,
 Mathf.Clamp(this.transform.position.z, -220f, -170f));

(This limits the movement of the car so that it will not go beyond a certain limit. The clamping ensures that when the car moves left or right, it will only more beyond a certain point)

        #region bank the player

        // Set rotation to local Angles
        Vector3 rotation = this.transform.localEulerAngles;

        //Set Velocity
        float velocity = 0.0F;

        // set the rotation on z to the input of the verticle buttons  using smoothDampAngle to:
        // Slowly rotate  when button is pressed and then return to orginal angle when button is released
        rotation.z = Mathf.SmoothDampAngle(rotation.z, -Input.GetAxis("Horizontal") * bankAngle, ref velocity, bankSpeed);
        transform.localEulerAngles = rotation;



        #endregion

        #region jump
//apply gravity
        dir.y = controller.velocity.y - gravityForce * Time.deltaTime;

//jump
         if (Input.GetKeyUp("space"))
        {
            dir.y = jumpForce * gravityForce * Time.deltaTime;
        }

        #endregion


    }


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.

Monday, 27 June 2011

As Shalini searched the internet for scripts, I decided to write the scripts for the movement of the car.

This is a basic layout:

using UnityEngine;
using System.Collections;

public class CarControls : MonoBehaviour
{
    #region Variables
    public float playerSpeed = 100;


    #endregion


    #region Update
    //Update per frame
    void Update()
    {
        // grab the left and right arrow key to move

        float horMov = Input.GetAxis("Horizontal") * playerSpeed * Time.deltaTime;
float verMov = Input.GetAxis("Vertical") * playerSpeed * Time.deltaTime;

        transform.position = new Vector3(this.transform.position.x +  horMov, 
                                               this.transform.position.y + verMov ,
                                               0);

    }
    #endregion
}

Monday, 23 May 2011

Test 5 answers

1. Tennis for Two, which was created in 1958 way before arcade games or other earlier video games existed.

2.  Mary, Queen of Scots, 1895

3. Modelling, Matte painting, Live-action effects, Digital animation

4. Matte Painting

5.

6. Assets is a toolbar in Unity that allows you to import or export a script as well as hook it to an object within the software in order to run the function.

7.

8.

9. It tells me what to do

10. Yes

Game design

We have decided to do a game which allows the user to drive a car as it avoids obstacles along the track by jumping. For each successfully dodged obstacle, 1 point is rewarded to the gamer. For every time the car collides into the barriers or enemies, a point is deducted.

1. The car has to jump over the enemies to score a point.

2. If it hits the enemy, it will explode and the player has to restart the level again.

3. For each increase in level, more obstacles will appear.







































Monday, 9 May 2011

Test 4 answers

1. We have finalized the game design. I have also updated my blog accordingly.

2. A game object is an empty group.

3. How far it can travel in time.

4.

Game Design

We are going to do a game where a car has to navigate an obstacle course by jumping and dodging enemies. 1 point is given for each successful dodge while a point is deducted if the car hits the enemy and explodes.