0 votes

All of my "is pressed" codes work just fine but none of the "is just pressed" codes work. What am i doing wrong? I'm making a 2D platformer
Heres my player code:

extends KinematicBody2D

const UP = Vector2(0, -1)
const GRAVITY = 15
const MAXSPEED = 125
const JUMP
HEIGHT = -300
var collisioninfo = moveand_collide(Vector2(0,0))
var motion = Vector2()

func physicsprocess(delta):
motion.y += GRAVITY
var friction = false

if Input.is_action_pressed("ui_right"):
    motion.x = min(motion.x+ACCELERATION, MAX_SPEED)
    $Sprite.flip_h = false
elif Input.is_action_pressed("ui_left"):
    $Sprite.flip_h = true
    motion.x = max(motion.x-ACCELERATION, -MAX_SPEED)
    friction = true

if is_on_floor():
    if Input.is_action_just_pressed("ui_up"):
        motion.y = JUMP_HEIGHT
    if friction == true: 
        motion.x = lerp(motion.x, 0, 0.18)
    if motion.y < 0:

if friction == true: 
    motion.x = lerp(motion.x, 0, 0.05)

if Input.is_action_just_pressed("ui_attack"):

motion = move_and_slide(motion, UP)
in Engine by (12 points)

1 Answer

0 votes

It may already played the animation and ended, so you have to loop the animation.

Also, it is better to put the play animation inside the process or _physicsprocess and have a variable checker there that is changed depending on the user's input.


var isJumping= false

func _ready():

func _input(delta):
    if Input.is_action_pressed("ui_up"):
        isJumping= true

    if Input.is_action_just_pressed("ui_up"):
        isJumping= false

func _process(delta):
    if isJumping:
by (26 points)
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 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 webmaster@godotengine.org with your username.