#Why is my Coyote Timing not working
1 messages · Page 1 of 1 (latest)
I'm trying to implement coyote timing to the brackeys game from some dudes tutorial
and one line is giving me an error
but I have it exact the same as he does
extends CharacterBody2D
const SPEED = 130.0
const JUMP_VELOCITY = -300.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 animated_sprite = $AnimatedSprite2D
@onready var coyote_timer = $CoyoteTimer
func _physics_process(delta):
# Add the gravity.
if not is_on_floor():
velocity.y += gravity * delta
# Handle jump.
if Input.is_action_just_pressed("jump") and (is_on_floor() || !coyote_timer.is_stopped()):
velocity.y = JUMP_VELOCITY
# Get the input direction: 1, 0, -1
var direction = Input.get_axis("move_left", "move_right")
var was_on_floor = is_on_floor()
velocity = move_and_slide(velocity, Vector2.UP)
if was_on_floor && !is_on_floor():
coyote_timer.start()
# Flip sprite
if direction > 0:
animated_sprite.flip_h = false
if direction < 0:
animated_sprite.flip_h = true
# Play animations
if is_on_floor():
if direction == 0:
animated_sprite.play("idle")
else:
animated_sprite.play("run")
else:
animated_sprite.play("jump")
# Apply movement
if direction:
velocity.x = direction * SPEED
else:
velocity.x = move_toward(velocity.x, 0, SPEED)
move_and_slide()
here is my player code
not sure why CoyoteTimer needs a double-negative function instead of a variable (!coyote_timer.is_stopped() instead of coyote_timer.is_active)?
What does CoyoteTimer look like (how did you make it)?
I made it from this guys tutorial
In this Godot tutorial I will show you how to add Coyote Time to a platformer.
Download the completed project here: https://github.com/stevepixelface/coyote-time
Direct download link: https://github.com/stevepixelface/coyote-time/archive/refs/heads/main.zip
Godot v3.4.4
⌛ Timestamps
0:00 Intro
0:24 Current Project Setup
1:20 Adding Coyote Tim...
is move_and_slide() a player script function? It's called twice; one after was_at_floor is instantiated and one at the end of the _physics_process()
how do I fix it?
1 sec, just trying it out
alr
I got it to work by using this function:
# gravity
if not is_on_floor():
velocity.y += gravity * delta
# jump
if Input.is_action_just_pressed("jump") and (is_on_floor() || !coyote_timer.is_stopped()):
velocity.y = JUMP_VELOCITY
coyote_timer.stop()
# input direction [-1,0,1]
var direction = Input.get_axis("move_left", "move_right")
# flip sprite
if direction > 0:
animated_sprite.flip_h = false;
elif direction < 0:
animated_sprite.flip_h = true;
# play animations
if is_on_floor():
if direction == 0:
animated_sprite.play("idle")
else:
animated_sprite.play("run")
else:
animated_sprite.play("jump")
# run
if direction:
velocity.x = direction * SPEED
else:
velocity.x = move_toward(velocity.x, 0, SPEED)
# move and slide
var was_on_floor = is_on_floor()
move_and_slide()
# coyote timer
if was_on_floor && !is_on_floor():
coyote_timer.start()
nice
so move_and_slide() changes the positions, then you check if the player's hovering to start the timer
if you want to stop your guy falling on the timer you can check if the coyote timer's still going at the gravity section
and why there is this "coyote_timer.stop()" in the Jump section
oh that's just to stop you being able to jump however many times you can in the timer period, so say, spam spacebar 10 times to jump really high
jump
var was_on_floor = is_on_floor()
if Input.is_action_just_pressed("jump") and (is_on_floor() || !coyote_timer.is_stopped()):
velocity.y = JUMP_VELOCITY
coyote_timer.stop()
was_on_floor = false
turns out you need to reposition was_on_floor to do that, oops
thank you
When you watch tutorials, make sure they are for godot 4