Wednesday, July 23, 2014

Dev Blog 22 - Fixed a small persistent issue

Fixed a persistent issue I had been having with some of the obstacles. The falling obstacles can kill the player just fine, regardless of if the player is moving or not. However the sideways spear obstacles and the "crushing platforms" obstacles had a issue where collisions were inconsistently detected when the player wasn't moving.

If the player was moving and hit one of these two problem obstacles, he would die guaranteed. But if the player stopped moving just before collision, death would sometimes not occur. I managed to solve the problem by reversing the way I was detecting collisions. Instead of checking from the Player.cs script to see if the player had hit any obstacles, I modified the obstacle's scripts to check if they had hit the player.

In order to do this I had to add Rigidbodies to the obstacles, which after collidiing with the player would get all screwy and rotated, so I had to take some additional steps to reset the obstacle properly after collision. Also the sideways spears would sometimes double, triple, or quadruple kill the player for a single collision. So I also had to write some code to temporarily disable the spear's collider on collision and then re-enable it later.

All of this was well worth the effort since collisions now occur with (as far as I can tell) 100% consistency.

Update: Just discovered the constraints you can set for rigidbodies, used Freeze Rotation so now I can go delete all of the rotation resetting code I wrote! Quite a nifty setting!

Update 2 @ 5PM: I inadvertently discovered some really cool behavior of the Crushing Platform obstacles. I had accidentally assigned the script responsible for the behavior twice to one of the gameObjects. The waitTime and repeatTime variables (responsible for how long the script waits to begin and how often it repeats, respectively) were different for each assignment of the script.

Normally 2 assignment of the same script would make the gameObject really screwy, but the behavior it created was actually very very cool. The platform would go up and come back down all the way, as expected. Then it would go up, and as it was coming back down, stop halfway and pause. It would stay paused for a second or two, and then come down all the day, and then repeat the entire process.

This "pause" effect created by the two script assignments effectively "fighting" with each other could actually fake out the player, make it seem like the platform is about to come down, then stop cold, making the player think it's safe to cross. And then just when the player might decide to go for it, BAM the platform comes crashing down! Totally unintentional but so very cool. Definitely going to spend some time playing with assigning the same script twice and seeing which values can create interesting behavior. The scripts "fighting" with each other doesn't seem to affect runtime or FPS noticeably, and no errors are coming up.

No comments:

Post a Comment