![]() |
Eye of the Nile Docs
Everything you need to know to get started!
|
Handles the player movement, such as walking and jumping, when the user presses the corresponding keys.
Documentation updated 10/8/2024
Implement features that make movement more smooth.
Add animation trigger for when the playing is falling (don't know if it should be its own animation or keep the last frame of the jump animation).
Fix bug: Make coyote time jump availability reset immediately after a jump without groundDetector overriding it.
Public Member Functions | |
void | Jump (float newJumpForce) |
Makes the player jump by canceling current velocity, adding upwards force, triggering the animation and sound effect, and setting isFalling to false. This jump allows for the amount of force applied to be specified. | |
Private Member Functions | |
void | Awake () |
Set references. | |
void | Start () |
Set linear drag in rigidbody to linearDrag, and jumpsAvailable to maxJumpChain. | |
void | Update () |
Determines how the player's movement should be processed this frame. See detailed view for steps. | |
void | Jump () |
Makes the player jump by canceling current velocity, adding upwards force, and setting isFalling to false. | |
Basic movement configuration | |
Information that can be configured in the Unity Editor to customize how the player moves.
| |
float | moveVelocity = 12.0f |
float | jumpForce = 10.0f |
The amount of force the player should jump with (how high does the player jump). | |
float | linearDrag = 1.0f |
The amount of linear drag that should be applied to the rigidbody. | |
float | maxJumpDuration = 0.2f |
How long the player is able to hold jump button before the jump stops increasing in power. | |
float | glideSpeed = -3.5f |
float | coyoteTime = 0.5f |
float | airTime = 0.0f |
The amount of time since the player was last on the ground. | |
float | jumpHeldDuration = 0.0f |
The amount of time the player has held the vertical input during a jump. Value is 0 if the player is not jumping. | |
bool | coyoteJumpAvailable = false |
Used to prevent multiple coyote jumps before the player returns to the ground. | |
bool | OnWarp = false [get, set] |
Double Jumping | |
Information related to jump chains (double jumping, tripple jumping, etc) and their functionality. | |
int | maxJumpChain = 1 |
Maximum amount of times the player can jump without touching the ground. | |
int | jumpsAvailable |
Amount of jumps still available in the jump chain before the player must touch the ground again to jump. | |
Reference Variables | |
These variables are references to other components on the player this script needs to communicate with. | |
Animator | animator |
Reference to the player's animator component. | |
PlayerHealth | objectHealth |
References to the player's PlayerHealth component. | |
Rigidbody2D | rb |
GroundDetector | groundDetector |
Reference to the player's GroundDetector - a small trigger zone beneath the player's feet that detects if the player is on the ground. | |
Sound Effect References | |
These variables are references to the sounds that should be played when certain movements or actions occur. | |
EventReference | jumpSFX |
|
private |
Set references.
|
private |
Makes the player jump by canceling current velocity, adding upwards force, and setting isFalling to false.
void PlayerMovement.Jump | ( | float | newJumpForce | ) |
Makes the player jump by canceling current velocity, adding upwards force, triggering the animation and sound effect, and setting isFalling to false. This jump allows for the amount of force applied to be specified.
newJumpForce | Amount of force to apply to the jump. |
|
private |
Set linear drag in rigidbody to linearDrag, and jumpsAvailable to maxJumpChain.
|
private |
Determines how the player's movement should be processed this frame. See detailed view for steps.
Steps:
float PlayerMovement.airTime = 0.0f |
The amount of time since the player was last on the ground.
Animator PlayerMovement.animator |
Reference to the player's animator component.
|
private |
Used to prevent multiple coyote jumps before the player returns to the ground.
float PlayerMovement.coyoteTime = 0.5f |
If the player walks off an edge, coyote time is the amount of time after leaving the ground that they can still jump. This prevents jumps from having to be frame perfect. The user gets a little bit of leniency with the timing of their jumps.
float PlayerMovement.glideSpeed = -3.5f |
The maximum velocity that the player can fall when vertical input is positive (gliding). More negative = faster fall.
|
private |
Reference to the player's GroundDetector - a small trigger zone beneath the player's feet that detects if the player is on the ground.
float PlayerMovement.jumpForce = 10.0f |
The amount of force the player should jump with (how high does the player jump).
|
private |
The amount of time the player has held the vertical input during a jump. Value is 0 if the player is not jumping.
|
private |
Amount of jumps still available in the jump chain before the player must touch the ground again to jump.
|
private |
float PlayerMovement.linearDrag = 1.0f |
The amount of linear drag that should be applied to the rigidbody.
int PlayerMovement.maxJumpChain = 1 |
Maximum amount of times the player can jump without touching the ground.
float PlayerMovement.maxJumpDuration = 0.2f |
How long the player is able to hold jump button before the jump stops increasing in power.
float PlayerMovement.moveVelocity = 12.0f |
The speed the player should walk at (how fast does the player walk).
PlayerHealth PlayerMovement.objectHealth |
References to the player's PlayerHealth component.
|
private |
Reference to the player's rigidbody component.
|
getset |
True if the player is standing over a warpable door. Currently used to prevent the player from jumping when trying to use a door. Use WarpInfo.CurrentlyWarping to check if the player is currently warping to another area through a StageWarp, such as a door or some other exit.