A lesson in how NOT to solve it


I introduced a stun-shot mechanism yesterday, only to find that it kept blowing up the player. It took me a while to understand that I had to not only deal with the stun's OnCollisionEnter() as having hit the player (in which case nothing is to happen), but also the player's OnCollision Enter() as the player having hit the stun (it's not supposed to register as a crash)

To the latter, I started adding code to find out if what the player hit was a stun-shot, and if so, find out if the stun-shot came from the player. Upon adding the code to find out if the hit car and the car who fired the stun were the same, I realized this "compensation" approach was miles too complicated. If another "what hit what" consideration-catching a powerup, for instance-were to come up, I'd have a labyrinth of "special cases".

So, I chose to Instantiate() shot with its collider disabled, set its velocity, and turn the collider on once the shot was clear of the car that fired it.

Naturally, a line from "Star Trek III: The Search for Spock" came to mind:

SCOTT:The more they overthink the plumbing, the easier it is to stop up the drain.

I wonder how many engineering professors have said something to that effect (*braces for it*).

Get GEMTrak

Download NowName your own price

Leave a comment

Log in with itch.io to leave a comment.