Mobile Game Progression
Creating spike Traps
In order to make the game progression more interesting for the player, instead of adding more enemies, we will be adding traps, spike traps to begin with.
Just like our static spike traps that we have implemented throughout the scene, the spike traps will also cause instead death to the player. The Only saving grace is that the traps are only lethal when the spikes are fully extended.
Animating the spike traps:
While it would have been easy to animate the spike traps via the position and scaling of the image, the only draw back is, if we were to create duplicates of the traps (which we will) the animation position is stuck to the original preset location and won’t appear on the newly set location. To avoid that conflict, my solution would be to create a sprite sheet of the spike rising manually.
With this setup I will be able to have the placement of the spike traps placed anywhere without affecting the position since the animation is in a self contained element.
I am next going to add a box collider 2D component to the spike trap and have the “is Trigger” function check on.
During the duration when the spike trap is fully exposed in the animation I am going to turn on the box collider for a few frames, otherwise the box collider is turned off.
Since we have already written a spike damage script, we can simply apply the same script we used for the static spikes for the trap spikes. The only modifications that we can add to the script would be to stop the spike animation after it has delicately pierced your player to prevent the player death animation from repeating over and over again.
During the collision of the player and the trap spike, we are going to trigger the player death animation and at the same time, set the trap animation speed to zero, basically making it freeze in place.
Now when your player unexpectedly walks up towards a trap spike, it will trigger the set effects.