Our great sponsors
-
InfluxDB
Power Real-Time Data Analytics at Scale. Get real-time insights from all types of time series data with InfluxDB. Ingest, query, and analyze billions of data points in real-time with unbounded cardinality.
The gist in most character controllers you see is: Every frame, use some sort of physics function* to see if the player is on the ground or not (i.e. isGrounded = true). If they are, and the player hits the jump key, set isJump = true, and isGrounded = false (and animate your jump etc) If they are already jumping (isJump == true), but isGrounded becomes true, set isJump = false, and stop your jump animation. There are various ways to check grounding. Could use a Raycast, Overlap Casts, A dedicated collider etc. The brackeys example (which I dislike for other reasons), shows this well enough: https://github.com/Brackeys/2D-Character-Controller/blob/master/CharacterController2D.cs
This is an example from my own code (a 3D FPS controller, same diff though) with double jumping: https://github.com/Hacksie/DarkSide/blob/main/Assets/Scripts/PlayerController.cs