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

Detailed Description

This script is used by a small trigger zone beneath some entities' feet (including the player) that detects if they are on the ground. When the entity is on the floor, isGrounded will be true.

NOTE: This detects the layer(s) selected on this script in the inspector, which is not necessarily the "Ground" layer! The selected layers should usually be set to "Ground" and "Collision" This script can only detect objects that have colliders.

Documentation updated 12/1/2024

Author
Stephen Nuttall, Alexander Art

Public Attributes

LayerMask groundLayer
 The layers which objects are considered part of the ground are on.
 

Properties

bool isGrounded = false [get, private set]
 True if the entity is touching the ground (after a small delay).
 
GameObject groundReference [get, private set]
 Reference to the ground the entity is on, if any.
 

Private Member Functions

void Awake ()
 Get reference to wall detector.
 
void OnTriggerEnter2D (Collider2D col)
 When the WallDetector detects the entity is not touching a wall, let isGrounded be set to true without the delay. Where there are no walls, isGrounded will not be falsely triggered by a wall. So, the isGroundedDelay can be bypassed.
 
void OnTriggerStay2D (Collider2D col)
 Runs when an object is inside the ground detector zone (Warning: slightly innacurate). If that object is on the groundLayer, increment groundTime. If groundTime is greater than the delay required to set isGrounded to true, then set isGrounded to true. If there is no longer a wall, bypass the delay.
 
void OnTriggerExit2D (Collider2D col)
 Runs when an object exits the ground detector zone. If that object is on the groundLayer, reset groundTime and set isGrounded to false.
 

Private Attributes

float isGroundedDelay = 0.025f
 
float groundTime = 0.0f
 Counts how long the entity has been on the ground.
 
WallDetectorInfo wallDetector
 Reference to the wall detector.
 

Member Function Documentation

◆ Awake()

void GroundDetector.Awake ( )
private

Get reference to wall detector.

◆ OnTriggerEnter2D()

void GroundDetector.OnTriggerEnter2D ( Collider2D col)
private

When the WallDetector detects the entity is not touching a wall, let isGrounded be set to true without the delay. Where there are no walls, isGrounded will not be falsely triggered by a wall. So, the isGroundedDelay can be bypassed.

Parameters
colRepresents the object inside the trigger zone.

◆ OnTriggerExit2D()

void GroundDetector.OnTriggerExit2D ( Collider2D col)
private

Runs when an object exits the ground detector zone. If that object is on the groundLayer, reset groundTime and set isGrounded to false.

Parameters
colRepresents the object inside the trigger zone.

◆ OnTriggerStay2D()

void GroundDetector.OnTriggerStay2D ( Collider2D col)
private

Runs when an object is inside the ground detector zone (Warning: slightly innacurate). If that object is on the groundLayer, increment groundTime. If groundTime is greater than the delay required to set isGrounded to true, then set isGrounded to true. If there is no longer a wall, bypass the delay.

Parameters
colRepresents the object inside the trigger zone.

Member Data Documentation

◆ groundLayer

LayerMask GroundDetector.groundLayer

The layers which objects are considered part of the ground are on.

◆ groundTime

float GroundDetector.groundTime = 0.0f
private

Counts how long the entity has been on the ground.

◆ isGroundedDelay

float GroundDetector.isGroundedDelay = 0.025f
private

How long the entity needs to be on the ground before isGrounded is set to true. This is necessary to prevent isGrounded being triggered by walls (bug).

◆ wallDetector

WallDetectorInfo GroundDetector.wallDetector
private

Reference to the wall detector.

Property Documentation

◆ groundReference

GameObject GroundDetector.groundReference
getprivate set

Reference to the ground the entity is on, if any.

◆ isGrounded

bool GroundDetector.isGrounded = false
getprivate set

True if the entity is touching the ground (after a small delay).


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