teaching machines

CS 491 Lab 4 – Circling

October 4, 2015 by . Filed under fall 2015, gamedev2, labs.

For the rest of the semester, we will alternate between labs devoted entirely to group work time and labs that involve an exercise related to game development. Last week was work time; this week is an exercise. I will try to craft the exercises to be general enough that you may be able to incorporate them into your final project.

Don’t forget the prospectus from last lab is due before October 6. It’s worth 1 Blugold!

Circle

In Rator Vaders, we recently added the ability to click the mouse anywhere on the screen, and then we automatically moved to our player to the mouse’s horizontal location. The jump wasn’t immediate. We spread it across many frames and used Vector3.Lerp to calculate the intermediate positions:


speed = ...

update:
  if mouse button just went up
    # Figure out where in the world the mouse is.
    mousePosition = Input.mousePosition
    worldPosition = Camera.main.ScreenToWorldPoint(mousePosition)
    worldPosition.z = 0

    # Go there in stages.
    start moveto worldPosition as a coroutine

moveto destination:
  source = transform.position
  distance = distance between destination and source
  eta = distance / speed
  startedAt = Time.time
  do
    elapsed = Time.time - startedAt
    proportion = elapsed / eta
    transform.position = lerp(source, distance, elapsed / eta)
    yield return null
  while proportion < 1.0

Today, you will do something similar. However, instead of moving your game object across a line (lerp = linear interpolation), you will move an object/character across a circle (slerp = spherical linear interpolation).

These are the requirements:

  1. Situation a game object on a circle. Maybe the circle represents a very small planet, a wheel, or a spinning space station? You decide.
  2. Let the player click on the screen using the mouse.
  3. Move the game object to the point on the circle closest to the mouse click. Alter transform.position directly using results from Vector3.Slerp—don’t use rigidbodies.
  4. The player of this demo should be presented with a challenge to overcome. Embed this mechanic in some game-like activity of your choosing.