![]() |
Attention | Topic was automatically imported from the old Question2Answer platform. |
![]() |
Asked By | Aby_is_a_kitkat |
hi, so I’m a little stumped on how to prevent the player character from moving when attacking. my goal is to make it so that the player stands still until the attack animation stops and then the player can proceed to move freely again. but right now if you hold a directional input like left or right the player will perform the attack animation and slide across the floor. you can see why this is not great. right now this is my code just in case someone can point out something I overlooked.
extends KinematicBody2D
"PLAYER CHARACTER CONTROLS"
const UP = Vector2(0,-1)
const GRAVITY = 35
const VELOCITY = 20
var motion = Vector2(0,0)
var walk_speed =Vector2(400,0)
var jump_height = Vector2(0,-900)
var jump_forward = Vector2(-400,-900)
var jump_backward = Vector2(400,-900)
var state_machine
func _ready():
state_machine = get_node("AnimatedSprite/AnimationPlayer/AnimationTree").get("parameters/playback")
func _physics_process(delta):
motion.y += GRAVITY
motion = move_and_slide(motion,UP)
if is_on_floor():
motion.y = 0
motion.x = 0
walk()
idle()
crouch()
jump()
attack_stand_punches()
attack_low_kicks()
attack_air_punches()
func walk():
if Input.is_action_pressed("ui_left"):
motion = -walk_speed
state_machine.travel("Walk Forward")
if Input.is_action_pressed("ui_right"):
motion = walk_speed
state_machine.travel("Walk Backwards")
func idle():
if motion == Vector2(0,0):
state_machine.travel("default")
func crouch():
if is_on_floor():
if Input.is_action_pressed("ui_down"):
state_machine.travel("Crouching idle")
motion.x = 0
elif Input.is_action_just_released("ui_down"):
idle()
func jump():
if Input.is_action_just_pressed("ui_up"):
motion = jump_height
state_machine.travel("Jump")
if Input.is_action_pressed("ui_left"):
state_machine.travel("Jump forward")
motion = jump_forward
elif Input.is_action_pressed("ui_right"):
state_machine.travel("Jump backwards")
motion = jump_backward
func attack_stand_punches():
if Input.is_action_pressed("ui_down") == false:
if Input.is_action_just_pressed("Mid Punch"):
state_machine.travel("mid punch")
motion.x = 0
attack_ground_movement_stop()
func attack_low_kicks():
if Input.is_action_pressed("ui_down"):
if Input.is_action_just_pressed("Mid Kick"):
state_machine.travel("low mid kick")
func attack_air_punches():
if _is_on_air():
if Input.is_action_just_pressed("Mid Punch"):
state_machine.travel("air punch")
Any help is greatly appreciated.