Devlog 3: Implementing the Energy Edge spell


Collisions

The script I was using  to cut meshes (it can be found in this open source package) required an exact collision point and the simplest method I could think of obtaining that information in Unity was through the OnCollisionEnter event and so I added a Rigidbody and non-trigger colliders to the energy blade object. I didn't want the projectile to be affected by other rigidbodies, and so set the isKinematic property of its Rigidbody to true. For the collision detection method, I had initially set it to Continuous Dynamic as it would be potentially interacting with other fast moving rigidbodies.

The first issue I encountered with this configuration was that the energy blade would call OnCollisionEnter continuously after passing through a fixed object. This was problematic as damage would be dealt multiple times instead of just once when the first OnCollisionEnter is called. To resolve this issue, I used a dictionary to keep track of each damageable object the projectile has collided with (the dictionary keys) and the last time a collision with the object was registered (the dictionary values). If the last collision was less than the Time.fixedDeltaTime + [small constant], then we ignore the event. I kept track of the last time a collision occurred in order to allow for multiple separate collisions with the same object (e.g. an enemy gets hit, then teleports backwards and gets hit again).

The second issue I encountered was that the first issue seemed to apply to different objects (i.e. the projectile passes through and destroys an enemy and then when a second enemy moves to where the previous enemy was located, it gets damaged even though the projectile is not touching it.) After getting frustrated and trying different possible solutions, I eventually tried changing the collision detection mode to Continuous and it ended up fixing both of the issues I had.

Releasing the energy blade

I wanted the energy projectile to be released from an imbued blade based on force as I felt it would add an element of skill to the spell and also be more fun to use than the alternatives (using a timer or a press of a button). Initially, I used a single threshold where if the speed at which the user is moving his/her controller surpasses the threshold, the projectile would be released. However, direction of the projectile ended up being incredibly difficult to control and so I ended up using 2 thresholds: after surpassing the first threshold, the projectile would be activated, and then after falling below the second threshold, the projectile would be release. This ended up being much easier to control than the previous method as the direction of the projectile tends to end near where the weapon swing ends.

Files

Drift Arena.zip 22 MB
25 days ago

Get Drift Arena

Leave a comment

Log in with your itch.io account to leave a comment.