0 votes

Hi, I'm new to Godot and have no other experience with coding;
can you please help a man out and tell me what's wrong with my coding?
I am unable to get the punching to work, and my player just stands there

extends KinematicBody2D

const UP = Vector2(0, -1)
const GRAVITY = 20
const JUMP_HEIGHT = -300
const SPEED = 300

var motion = Vector2()

var is_punching = false

func process(delta):
if Input.is
actionpressed("uip"):
ispunching = true
$Sprite.play("punch1")
func _on
Spriteanimationfinished():
is_punching = false

print(is_punching)

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

if Input.is_action_pressed("ui_right"):
    motion.x = SPEED
    $Sprite.flip_h = true
    $Sprite.play("walk")
elif Input.is_action_pressed("ui_left"):
    motion.x = -SPEED
    $Sprite.flip_h = false
    $Sprite.play("walk")
else:
    motion.x = 0
    $Sprite.play("Idle")

if is_on_floor():
    if Input.is_action_just_pressed("ui_up"):
        motion.y = JUMP_HEIGHT
else:
    $Sprite.play("Jump")

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

have you correctly mapped the action "ui_p" in your project settings ?

I don't see anything wrong with your code.

1 Answer

0 votes

you mean your player still moves while punching when you don't want? than add:
"if not is punching:"
if you want player to not do anything, add it before if input....

by (82 points)

I meant that the player doesn't punch at all, any clues as to why not?

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.