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
- A collision between two or more objects which does not suffer from momentum or kinetic energy force.
- Inelastic collisions are the opposite of elastic collisions, i.e. they suffer from momentum / kinetic energy loss.
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 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 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
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.
Below is a GIF of my implementation:
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.
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.
Subscribe to my mailing list to receive updates about my projects!