Attention | Topic was automatically imported from the old Question2Answer platform. | |
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
$Sprite.play(“punch1”)
func _on_Sprite_animation_finished():
is_punching = false
print(is_punching)
func _physics_process(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)
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