Godot Version
4.2.2
Question
i tired to apply the code from this post: Coyote Time with CharacterBody2D into my own game, but my character doesn’t jump during coyote time, i even set the timer’s wait time excessively high (0.5 secs) and made sure that it’s timeout is called, but still nothing.
extends CharacterBody2D
var speed = 300.0
const JUMP_VELOCITY = -400.0
signal died
@export var has_camera=true
@export var death_position=1000
var can_jump
# Get the gravity from the project settings to be synced with RigidBody nodes.
var gravity = ProjectSettings.get_setting("physics/2d/default_gravity")
func _ready():
if has_camera:
add_child(Camera2D.new())
func _physics_process(delta):
if position.y>=death_position:
emit_signal("died")
# Add the gravity.
if not is_on_floor():
velocity.y += gravity * delta
if is_on_floor():
speed=300
can_jump=true
if (is_on_floor() == false) and can_jump and $JumpTimer.is_stopped():
$JumpTimer.start()
can_jump=true
# Handle jump.
if Input.is_action_just_pressed("ui_accept") and is_on_floor():
speed=400
position.y -= 15
velocity.y = JUMP_VELOCITY
can_jump=false
var direction = Input.get_axis("ui_left", "ui_right")
if direction:
velocity.x = direction * speed
else:
velocity.x = move_toward(velocity.x, 0, speed)
move_and_slide()
func _on_hurt_box_body_entered(body):
emit_signal("died")
func _on_jump_timer_timeout():
can_jump=false