0 votes

So yeah, I need help implementing Coyote Jumping but tutorials on YouTube ain't helping at all. :(((
I'm a beginner so my code is messy :((
Can anyone tell me the code and where to put it??? (Nodes or codes )

extends KinematicBody2D

const UP = Vector2(0, -1)
const GRAVITY = 20
const MAX_SPEED = 100
const JUMP = -300
const ACCELERATION = 50

onready var animationPlayer = $AnimationPlayer

var motion = Vector2()

var is_dead = false

func physicsprocess(_delta):
motion.y += GRAVITY

if is_dead == false:
    if Input.is_action_pressed("ui_right"):
        motion.x = min(motion.x+ACCELERATION, MAX_SPEED)
        animationPlayer.play("Walk")

    elif Input.is_action_pressed("ui_left"):
        motion.x = max(motion.x-ACCELERATION, -MAX_SPEED)
        animationPlayer.play("WalkLeft")

    if Input.is_action_just_pressed("ui_quit"):
        get_tree().quit()

    if Input.is_action_just_released("ui_right"):
        motion.x = 0
        animationPlayer.play("IdleRight")

    elif Input.is_action_just_released("ui_left"):
        motion.x = 0
        animationPlayer.play("IdleLeft")

    if is_on_floor():
        if Input.is_action_just_pressed("ui_up"):
            motion.y = JUMP

    motion = move_and_slide(motion, UP)
    pass

    if get_slide_count() > 0:
        for i in range(get_slide_count()):
            if "Enemy" in get_slide_collision(i).collider.name:
                dead()

func dead():
is_dead = true
motion = Vector2(0, 0)
$CollisionShape2D.disabled = true
$Timer.start()

func onTimertimeout():
get
tree().change_scene("res://Scene/Levels/World1.tscn")

if Input.is_action_just_pressed("ui_quit"):
    get_tree().quit()
in Engine by (14 points)

1 Answer

0 votes

tutorials on YouTube ain't helping at all

I just searched on YouTube for "godot coyote time", the first hit was this video, the second was this. Both videos explain it pretty well, so: not true.

Anyways, here you go:

extends KinematicBody2D

const ACCELERATION = 50
const MAX_SPEED = 100
const GRAVITY = 20
const JUMP = -300    

var motion = Vector2()
var is_jumping = false
var coyote_time    

func _ready():
    coyote_time = Timer.new()
    coyote_time.one_shot = true
    coyote_time.wait_time = 2.0
    add_child(coyote_time)

func _physics_process(_delta):
    if Input.is_action_pressed("ui_right"):
        motion.x = min(motion.x+ACCELERATION,  MAX_SPEED)
    elif Input.is_action_pressed("ui_left"):
        motion.x = max(motion.x-ACCELERATION, -MAX_SPEED)
    else:
        motion.x = 0

    if coyote_time.is_stopped():
        motion.y += GRAVITY

    if is_on_floor():
        is_jumping = false
        if Input.is_action_just_pressed("ui_up"):
            is_jumping = true
            motion.y = JUMP

    var was_on_floor = is_on_floor()
    motion = move_and_slide(motion, Vector2.UP)
    if not is_on_floor() and was_on_floor and not is_jumping:
        coyote_time.start()
        motion.y = 0
by (10,608 points)

The first video, you get an error if you use yield. The second video just doesn't work with some people's code (including mine).

Welcome to Godot Engine Q&A, where you can ask questions and receive answers from other members of the community.

Please make sure to read Frequently asked questions and How to use this Q&A? before posting your first questions.
Social login is currently unavailable. If you've previously logged in with a Facebook or GitHub account, use the I forgot my password link in the login box to set a password for your account. If you still can't access your account, send an email to [email protected] with your username.