I am a complete beginner ( few days into code ) and i'm stuck for a couple of days now.
The issue = my character doesnt stop moving on X when i hold jump after a walking jump. Like it's freaking out over double inputs.
I can solve it my placing my jump script seperately in inputevent instead of _physicsprocess(delta). But then my jumping animation doesnt work, but the running animation does.
I tried putting everything in input_event but then it's stuck all completely.
I'm missing something basic here but i cant put my finger on it.
Script:
extends KinematicBody2D
const SPEED = 100
const GRAVITY = 10
const JUMPPOWER = -150
const FLOOR = Vector2(0, -1)
var velocity = Vector2()
var onground = false
func jump():
velocity.y = -JUMP_POWER
func input(event):
if event.isactionpressed("uiup"):
if isonfloor():
velocity.y = JUMP_POWER
$AnimatedSprite.play("jump")
func physicsprocess(_delta):
if Input.is_action_pressed("ui_right"):
velocity.x = SPEED
if is_on_floor():
$AnimatedSprite.play("walking")
$AnimatedSprite.flip_h = false
elif Input.is_action_pressed("ui_left"):
velocity.x = -SPEED
if is_on_floor():
$AnimatedSprite.play("walking")
$AnimatedSprite.flip_h = true
else:
velocity.x = 0 # Stops the left/right movement on
if is_on_floor():
$AnimatedSprite.play("idle")
velocity = move_and_slide(velocity, FLOOR)
velocity.y += GRAVITY
if is_on_floor():
on_ground = true
else:
on_ground = false