What's wrong with my code?

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By Jeejus

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_action_pressed(“ui_p”):
is_punching = true
func _on_Sprite_animation_finished():
is_punching = false


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

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

if is_on_floor():
	if Input.is_action_just_pressed("ui_up"):
		motion.y = JUMP_HEIGHT

motion = move_and_slide(motion, UP)

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

I don’t see anything wrong with your code.

Joel_127 | 2019-04-26 11:16

:bust_in_silhouette: Reply From: ProXFox

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…

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

Jeejus | 2019-04-26 05:25