Home » Previous Subjects » Spring 2014 – Game Design » More Basics, Intro to Scripting

More Basics, Intro to Scripting

This week we created a simple game where we have a horizontal surface (ground), a ball, a camera, a light source, and the ability to move the ball along the ground.  The ball obeys physics, and when it reaches the edge of the ground, it falls.

It was a good review, as it’s been a week and a half since we worked with the tools.  The review included the following areas:

  • The Scene, Scene View, Inspector, and Console windows
  • Saving Projects vs. Saving Scenes
  • The problems with editing while the game is playing (your changes are lost)
  • How to move around in the Scene view (using Alt or Ctrl-Alt)

 

Once we created our objects, we added a Physics — RigidBody to the ball, making it obey gravity.  We then added a script to it.  We used Javascript as the language, though in the future we will use C#.

Here is the script we used:

#pragma strict
var rotationSpeed = 200;
function Update () {
 var rotation : float = Input.GetAxis("Horizontal") * rotationSpeed;
 rotation *= Time.deltaTime;
 rigidbody.AddRelativeForce(Vector3.back * rotation);
}

There were some problems with our script and the game didn’t quite work as intended, but we still learned quite a bit from the experience.

Leave a Reply

Your email address will not be published. Required fields are marked *