![]() |
Eye of the Nile Docs
Everything you need to know to get started!
|
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
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. | |
|
private |
Get reference to wall detector.
|
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.
col | Represents the object inside the trigger zone. |
|
private |
Runs when an object exits the ground detector zone. If that object is on the groundLayer, reset groundTime and set isGrounded to false.
col | Represents the object inside the trigger zone. |
|
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.
col | Represents the object inside the trigger zone. |
LayerMask GroundDetector.groundLayer |
The layers which objects are considered part of the ground are on.
|
private |
Counts how long the entity has been on the ground.
|
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).
|
private |
Reference to the wall detector.
|
getprivate set |
Reference to the ground the entity is on, if any.
|
getprivate set |
True if the entity is touching the ground (after a small delay).