Hey there, im a developer in Godot who is making a small game for the Bigmode Game Jam, it’s going decent so far for me, but im having extreme trouble with smoothening the movement of my Long Jump. It feels like no matter how hard I try, I can’t make it feel janky.
The issue right now is that whenever the player longjumps (not referring to regular jump, that works fine), instead of smoothly moving from point A to point B, the player just teleports to point B instantly, and it looks really bad.
I’m at the point where I might just scrap the long-jump movement, but I figured I may aswell post here for help as a last resort beforehand to see if I can find a solution to get the code to make the longjump smooth.
If any of you know how to fix this, please let me know.
Thanks.
Here’s the code: extends KinematicBody2D
const UP_DIRECTION := Vector2.UP
onready var sprite = $AnimatedSprite
export var speed := 100
export var gravity := 400
export var jump_strength := 150
export var max_fall_speed := 180
var _velocity := Vector2.ZERO
var wallJump := 190
var bounceoff := 30
export var double_jump_strength = 140
var maxJumps := 2
var jumpsMade := 0
var acceleration = 200
var longjumpdistance = 500
var WJlimit := 1
var WJcount := 0
func _physics_process(delta: float) -> void:
var _horizontal_direction = (
Input.get_action_strength("move_right")
- Input.get_action_strength("move_left")
)
if Input.is_action_pressed("move_left"):
sprite.set_flip_h(true)
if Input.is_action_pressed("move_right"):
sprite.set_flip_h(false)
_velocity.x = _horizontal_direction * speed
_velocity.y += gravity * delta
var is_falling := _velocity.y > 0.0 and not is_on_floor()
var is_double_jumping := Input.is_action_just_pressed("jump") and is_falling
var is_jumping := Input.is_action_just_pressed("jump") and is_on_floor()
var is_sliding = is_on_wall() and not is_on_floor() and _horizontal_direction
var is_jump_cancelled := Input.is_action_just_released("jump") and _velocity.y < 0.0
var is_idling := is_on_floor() and is_zero_approx(_velocity.x)
var is_running := is_on_floor() and not is_zero_approx(_velocity.x)
var is_bursting := is_on_wall() and WJcount == 0 and not is_on_floor() and Input.is_action_pressed("move_right") or Input.is_action_pressed("move_left") and Input.is_action_just_pressed("jump")
var is_longjumping := is_on_floor() and not is_on_wall() and Input.is_action_just_pressed("longjump")
if is_jumping:
jumpsMade += 1
_velocity.y = -jump_strength
elif is_double_jumping:
jumpsMade += 1
if jumpsMade <= maxJumps:
_velocity.y = -double_jump_strength
elif is_jump_cancelled:
_velocity.y = 0.0
if is_longjumping:
_velocity.x = lerp(_velocity.x, _horizontal_direction * longjumpdistance, acceleration * delta)
if is_sliding:
max_fall_speed = 40
else:
max_fall_speed = 180
if is_on_wall() and WJcount == 0 and not is_on_floor() and Input.is_action_pressed("move_left") and Input.is_action_just_pressed("jump"):
_velocity.y = -wallJump
WJcount = 1
if is_on_wall() and WJcount == 0 and not is_on_floor() and Input.is_action_pressed("move_right") and Input.is_action_just_pressed("jump"):
_velocity.y = -wallJump
WJcount = 1
if _velocity.y > max_fall_speed:
_velocity.y = max_fall_speed
_velocity = move_and_slide(_velocity, UP_DIRECTION)
if is_jumping:
sprite.play("Jump")
elif is_sliding:
sprite.play("Wallslide")
elif is_running:
sprite.play("Run")
jumpsMade = 0
WJcount = 0
elif is_idling:
jumpsMade = 0
WJcount = 0
sprite.play("Idle")