Simulation in Games: Week 7

In this week’s blog post, we will look at the last of the Simulation in Games topics – Collision types, momentum, reflective vectors and bouyancy! I will also go over how the fireball spell works!

Collision Types, Momentum, Reflective Vectors and Buoyancy

Collision Types

Elastic Collisions

  • A collision between two or more objects which does not suffer from momentum or kinetic energy force.

Inelastic Collisions

  • Inelastic collisions are the opposite of elastic collisions, i.e. they suffer from momentum / kinetic energy loss.

Momentum

The quantity of motion of an object, i.e. the “mass in action”. The equation to calculate an object’s momentum is:

  • momentum = mass * velocity

Reflective Vectors

Reflective vectors are mirror copies of a different vector (the original) in regards to the normal of a reflective surface.

Reflective vectors and momentum can be used to calculate the velocity of an object after collision.

Buoyancy

Buoyancy is an upward reaction force exerted by a fluid that opposes the weight of an immersed object.

To determine the buoyance of a submerged object, we apply Archimedes’ principle:

  • buoyance = density * volume * gravity

Exercise

The Tasks

This week we were tasked with creating a Unity scene which contains:

  • A cannon which shoots projectiles that:
    • are affected by a global gravity.
    • have an initial velocity.
    • have momentum and buoyancy properly implemented.
  • A set of walls to help test momentum.
  • A “water” object for testing buoyancy.

The Implementation

Below is a GIF of my implementation:

Momentum and Buoyancy

Spellcaster Academy

Fireball Spell

After this week’s topic, I decided to rethink the way I was going to implement the fireball spell. The final implementation I came up with is as follows:

  • When an enemy (or targetable object, such as a wall) is clicked on, the Interaction class’ OnRightClick event will send a message to the player’s CastSpell method.
  • For now, the method defaults to the fireball spell, but will trigger any implemented spell once I implement a spell menu into the UI/HUD.
  • Fireball spell functionality is implemented as a coroutine. Provided the player does not move, an instance of the Fireball prefab will be spawned in. The fireball will have an initial velocity in the normalised direction of the target and a speed of 30 units.

Reflective Surfaces

Fireball reflective

I managed to get reflective surfaces working as part of custom Properties and Dynamic Objects classes. As the fireballs have the Dynamic Object class, they will be bounced off after colliding with a surface that has the Properties class. This uses a formula which combines reflective vectors and momentum. Currently the fireballs can bounce off walls and the Goblin’s shields. How exciting!

Anyway, tune in next week for more updates.

Written on March 14, 2018 | Tagged: Simulation in Games

Mailing list

Subscribe to my mailing list to receive updates about my projects!