Eye of the Nile Docs
Everything you need to know to get started!
Loading...
Searching...
No Matches
SquasherHazard Class Reference

Detailed Description

Script for the squasher hazard. When the player enters the squasher's trigger zone, it falls under gravity. When the squasher hits the ground, it stays there for a moment before returning. This script goes on the trigger zone of the squasher hazard.

Documentation updated 12/24/2024

Author
Alexander Art
Todo
Fix bug: If the player stays under the squasher without leaving the trigger zone, the squasher doesn't re-squash.

Public Attributes

float fallSpeed = 1f
 The gravity scale at which the squasher will fall.
 
float returnSpeed = 3f
 The speed at which the squasher returns to its starting position.
 
bool allowFallCancel = false
 Set to true to let the squasher stop falling the moment player exits its trigger zone. If false, it can't stop falling until it hits the ground.
 
bool allowReturnCancel = false
 Set to true to allow the squasher start falling while it's returning to its starting position. If false, it can't start falling until it's at its starting position.
 
float groundTime = 1.5f
 When the squasher hits the ground, this is how long it stays stuck to the ground (measured in seconds).
 

Private Member Functions

void Update ()
 Handle the logic for the four states that the squasher can be in:
 
void OnTriggerEnter2D (Collider2D col)
 When the player enters the squasher's trigger zone and the squasher is ready to fall, make it fall. The squasher is considered ready to fall when:
 
void OnTriggerExit2D (Collider2D col)
 If the squasher is allowed to cancel its falling state, then when the player leaves the trigger zone, let it go back to its starting position (sets state to "RETURNING").
 

Private Attributes

GameObject squasher
 The squasher hazard that falls when it detects a player.
 
GameObject fallingDamageHitbox
 Hitbox on the bottom of the squasher that will only be active when the squasher is falling.
 
GameObject crushingHitbox
 Hitbox within the squasher that can only hurt the player if the player clips into the squasher. Always active, but usually only affects the player when the player gets pushed into the ceiling by the squasher.
 
GameObject returnPoint
 The point that the squasher will return to after falling.
 
float groundTimeCounter = 0f
 Keeps track of how long the squasher has been on the ground (measured in seconds).
 
string state = "IDLE"
 The four states the squasher can be in are "IDLE", "FALLING", "GROUNDED", and "RETURNING". It will typically cycle through these four states.
 

Member Function Documentation

◆ OnTriggerEnter2D()

void SquasherHazard.OnTriggerEnter2D ( Collider2D col)
private

When the player enters the squasher's trigger zone and the squasher is ready to fall, make it fall. The squasher is considered ready to fall when:

  • It is idle (at its starting position) OR
  • it is returning to its starting position and is allowed to cancel its returning state.
Parameters
colRepresents the object that entered the trigger zone.

◆ OnTriggerExit2D()

void SquasherHazard.OnTriggerExit2D ( Collider2D col)
private

If the squasher is allowed to cancel its falling state, then when the player leaves the trigger zone, let it go back to its starting position (sets state to "RETURNING").

Parameters
colRepresents the object that entered the trigger zone.

◆ Update()

void SquasherHazard.Update ( )
private

Handle the logic for the four states that the squasher can be in:

  • "IDLE":
    • Keep the squasher still, prevent it from dealing falling damage, and wait for the player to enter its trigger zone.
  • "FALLING":
    • Let the squasher fall, let it deal falling damage, and wait for it be on the ground.
  • "GROUNDED":
    • Let the squasher fall if at all possible, but prevent it from dealing falling damage.
    • Once some time passes, set the squasher's state to "RETURNING".
  • "RETURNING":
    • Move the squasher upwards and prevent it from dealing falling damage.
    • Once the squasher is in its starting position, set its state to "IDLE".

Member Data Documentation

◆ allowFallCancel

bool SquasherHazard.allowFallCancel = false

Set to true to let the squasher stop falling the moment player exits its trigger zone. If false, it can't stop falling until it hits the ground.

◆ allowReturnCancel

bool SquasherHazard.allowReturnCancel = false

Set to true to allow the squasher start falling while it's returning to its starting position. If false, it can't start falling until it's at its starting position.

◆ crushingHitbox

GameObject SquasherHazard.crushingHitbox
private

Hitbox within the squasher that can only hurt the player if the player clips into the squasher. Always active, but usually only affects the player when the player gets pushed into the ceiling by the squasher.

◆ fallingDamageHitbox

GameObject SquasherHazard.fallingDamageHitbox
private

Hitbox on the bottom of the squasher that will only be active when the squasher is falling.

◆ fallSpeed

float SquasherHazard.fallSpeed = 1f

The gravity scale at which the squasher will fall.

◆ groundTime

float SquasherHazard.groundTime = 1.5f

When the squasher hits the ground, this is how long it stays stuck to the ground (measured in seconds).

◆ groundTimeCounter

float SquasherHazard.groundTimeCounter = 0f
private

Keeps track of how long the squasher has been on the ground (measured in seconds).

◆ returnPoint

GameObject SquasherHazard.returnPoint
private

The point that the squasher will return to after falling.

◆ returnSpeed

float SquasherHazard.returnSpeed = 3f

The speed at which the squasher returns to its starting position.

◆ squasher

GameObject SquasherHazard.squasher
private

The squasher hazard that falls when it detects a player.

◆ state

string SquasherHazard.state = "IDLE"
private

The four states the squasher can be in are "IDLE", "FALLING", "GROUNDED", and "RETURNING". It will typically cycle through these four states.


The documentation for this class was generated from the following file: