Simulation in Games: Week 4

Another week, another blog post. This one is all about projectile and simple harmonic types of motion and my decision to change the game up a bit. Read on!

Projectile and Simple Harmonic Motion

Projectile Motion

Projectile motion is the motion of an object thrown or projected into the air in a curved or parabolic path, subject only to the acceleration of gravity.

Without air resistance, or any other external force, the horizontal velocity of the thrown projectile will be constant.

Simple Harmonic Motion

Simple Harmonic Motion is an oscillatory motion under a retarding force. The force is proportional to the amount of displacement from an equilibrium position.

To implement simple harmonic motion in Unity, we follow the steps below.

1. First, we define some variables that will be used to set up the motion:

float speed = 2;
float amplitude = 5;
Vector3 equilibriumPoint = new Vector3 (3,5,0);
Vector3 velocity;

2. Then, we define the velocity based on the type of motion desired:

  • Horizontal (X axis)
velocity.x = (Mathf.Sin(Time.time * speed) * amplitude) + equilibriumPoint.x;
  • Vertical
velocity.y = (Mathf.Sin(Time.time * speed) * amplitude) + equilibriumPoint.y;
  • Diagonal (X axis)
velocity.x = (Mathf.Sin(Time.time * speed) * amplitude) + equilibriumPoint.x;
velocity.y = (Mathf.Sin(Time.time * speed) * amplitude) + equilibriumPoint.y
  • Circular (X axis)
velocity.x = (Mathf.Sin(Time.time * speed) * amplitude) + equilibriumPoint.x;
velocity.y = (Mathf.Cos(Time.time * speed) * amplitude) + equilibriumPoint.y

3. Finally, we set the velocity as the object’s position multiplied by time:

transform.position = velocity * Time.deltaTime;

Exercise

No exercise this week!

Spellcaster Academy

So, I’ve been doing some thinking and… As I’ve previously made a first person puzzle game (Robotrooper: Survival), I thought Spellcaster Academy would be a good opportunity to try out something different. As such, Spellcaster Academy will be a point and click player versus monster game instead!

Interaction

I’ve already begun planning the inner workings of a point and click gameplay system - an Interaction class which will be attached to all interactable objects within the game. The class’s functionality will be variable based on an enum value (i.e., the ground’s enum value will be “Ground”, the enemies will be marked with “Enemy”, etc.). Whenever an object with the Interaction class component is clicked using the mouse, an event will be triggered (either OnLeftClick or OnRightClick). The player class will have listeners for both of these events and will trigger them accordingly.

Anyhow, more on that next week. In the meantime, please enjoy these cursors I made for the mouse interactions:

Spellcaster Academy Cursors

Thanks for reading. See you next week!

Written on February 20, 2018 | Tagged: Simulation in Games