Godot Version
4.5.stable
Question
I figured out how to implement Coyote Time, but coyote jumps are much shorter than jumps from platform and I don’t understand why it’s happening.
extends CharacterBody2D
var direction_x: float
var speed := 120
var jump_strength:=350
var gravity:=700
var can_jump:=false
signal shoot(pos: Vector2, dir: Vector2)
const gun_dir = {
Vector2i(1, 0): 0,
Vector2i(1, 1): 1,
Vector2i(0, 1): 2,
Vector2i(-1, 1): 3,
Vector2i(-1, 0): 4,
Vector2i(-1, -1): 5,
Vector2i(0, -1): 6,
Vector2i(1, -1): 7,
}
func get_input():
direction_x = Input.get_axis("left", "right")
if is_on_floor() and can_jump==false:
can_jump = true
if Input.is_action_just_pressed("jump") and can_jump==true:
velocity.y -= jump_strength
if Input.is_action_just_released("jump") and velocity.y<0:
velocity.y = -0.001
if Input.is_action_pressed("shoot") and $Node/ReloadTimer.time_left==0:
shoot.emit(position, get_local_mouse_position().normalized())
$Node/ReloadTimer.start()
var tween = get_tree().create_tween()
tween.tween_property($Marker, "scale", Vector2(0.1,0.1), 0.05)
tween.tween_property($Marker, "scale", Vector2(0.5,0.5), 0.24)
$Marker.rotation +=90
if is_on_floor():
speed=120
elif Input.is_action_pressed("jump") and velocity.y<0:
speed=150
if is_on_floor()==false and $Node/CoyoteTime.is_stopped():
$Node/CoyoteTime.start()
if velocity.y<0:
can_jump = false
func legs():
if velocity:
if is_on_floor() and velocity.x !=0:
$Legs.animation = "run"
$Legs.flip_h = velocity.x<0
else:
$Legs.animation = "jump"
else:
$Legs.animation = "idle"
func torso():
var raw_dir:= get_local_mouse_position().normalized()
var round_dir:=Vector2i(round(raw_dir.x), round(raw_dir.y))
$Torso.frame = gun_dir[round_dir]
func marker():
$Marker.position = get_local_mouse_position()
func apply_gravity(delta):
velocity.y += gravity*delta
if is_on_floor()==false:
velocity.y += gravity*delta*0.125
func _physics_process(delta: float) -> void:
velocity.x = direction_x * speed
get_input()
legs()
torso()
marker()
apply_gravity(delta)
move_and_slide()
func _on_coyote_time_timeout() -> void:
can_jump = false