0 votes

Here is the code: please help!

extends KinematicBody2D

const SPEED = 100
const GRAVITY = 10
const JUMP_POWER = -250
const FLOOR = Vector2(0, -1)
var isAttacking = false

var velocity = Vector2()

var on_ground = false

func _physics_process(delta):
    if Input.is_action_pressed("ui_right") && isAttacking == false:
        velocity.x = SPEED
        $AnimatedSprite.flip_h = false
    if Input.is_action_pressed("ui_left") && isAttacking == false:
            velocity.x = -SPEED
            $AnimatedSprite.flip_h = true
        velocity.x = 0
        if on_ground == true:
            if isAttacking ==false:

    if Input.is_action_pressed("ui_up"):
        if on_ground == true:
            velocity.y = JUMP_POWER
            on_ground = false
    if Input.is_action_just_pressed("Attack"):
        if on_ground == true:
            isAttacking = true

    velocity.y += GRAVITY

    if is_on_floor():
        on_ground = true
        on_ground = false
        if velocity.y < 0:

    velocity = move_and_slide(velocity, FLOOR)

func _on_AnimatedSprite_animation_finished():
    if $AnimatedSprite.animation == "Attack":
        isAttacking = false
in Engine by (14 points)
edited by

Because gdscript is indent-sensitive, it's really difficult to point out potential script problems in unformatted code. Please edit your post and format the code. To do that, just select all of the code and press the { } button in the editor's toolbar.

Hi, thanks for that.

1 Answer

0 votes

Is your variable "onground" true when you press "uiright"?

If "on_ground" is true, I don't see anything wrong, maybe your node is already colliding with another one, and that keeps him from moving?

If you have nodes in your scene that can collide with your character, try disabling them. Just keep the ground and test.

by (55 points)

Hi thanks for the reply. Still no luck. Pressing right turns the character but freezes in space. What is confusing is that when the if statement for uileft is taken out, then uiright works fine.

Solved! I changed the second "if" to "elif".

Thanks for the help!

Yes... I did not see the if ... if ... else!

Good if you solved your problem!!!

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.