Godot Version
godot v4.2.1
Question
I tried to add coyote jump to buılt in character controller code but it just lets you to jump infinitely
here is the code:
extends CharacterBody2D
var SPEED = 400.0
const JUMP_VELOCITY = -600.0
Get the gravity from the project settings to be synced with RigidBody nodes.
var gravity = ProjectSettings.get_setting(“physics/2d/default_gravity”)
@onready var cyt = $cyt
func _physics_process(delta):
# Add the gravity.
var was_on_floor= is_on_floor()
if not is_on_floor():
velocity.y += gravity * delta
# Handle jump.
if Input.is_action_just_pressed("jump"):
if is_on_floor() or cyt.time_left>0.0:
velocity.y = JUMP_VELOCITY
print(cyt.time_left)
# Get the input direction and handle the movement/deceleration.
# As good practice, you should replace UI actions with custom gameplay actions.
var direction = Input.get_axis("left", "right")
if direction:
velocity.x = direction * SPEED
else:
velocity.x = move_toward(velocity.x, 0, SPEED)
move_and_slide()
var jll= was_on_floor and not is_on_floor() and velocity.y>=0
if jll:
cyt.start()
print(was_on_floor==is_on_floor())