@TwistedTwigleg said:
I only glanced through the code, but what you could try doing is disabling looking for input while the character is rolling, at least for movement input. Another thing you could try is checking to see if the player is rolling already and if they are, not setting the state to MOVE
.
I solved the problem but in a very dirty way, maybe this method is not the most optimized, if someone sees this in the future please try to develop better methods, I was only able to think of this super simple way for my code
I added the complete code for beginners to analyze and study ;)
extends KinematicBody2D
export var ACCELERATION = 500
export var MAX_SPEED = 80
export var ROLL_SPEED = 120
export var FRICTION = 500
var input_forward_data = {
"taps":0,
"taps2":0,
"taps3":0,
"taps4":0,
"timer":0,
"reset_time":1
}
enum{
MOVE,
ROLL,
ATTACK
}
var tatata = null
var state = MOVE
var velocity = Vector2.ZERO
var roll_vector = Vector2.DOWN
onready var animationPlayer = $AnimationPlayer
onready var animationTree = $AnimationTree
onready var animationState = animationTree.get("parameters/playback")
onready var swordHitbox = $HitboxPivot/SwordHitbox
func _ready():
animationTree.active = true
swordHitbox.knockback_vector = roll_vector
func _process(delta):
match state:
MOVE:
move_state(delta)
ROLL:
roll_state(delta)
ATTACK:
attack_state(delta)
func move_state(delta):
var input_vector= Vector2.ZERO
input_vector.x = Input.get_action_strength("ui_right") - Input.get_action_strength("ui_left")
input_vector.y = Input.get_action_strength("ui_down") - Input.get_action_strength("ui_up")
input_vector = input_vector.normalized()
if input_vector != Vector2.ZERO:
roll_vector = input_vector
swordHitbox.knockback_vector = input_vector
animationTree.set("parameters/Idle/blend_position", input_vector)
animationTree.set("parameters/Run/blend_position", input_vector)
animationTree.set("parameters/Attack/blend_position", input_vector)
animationTree.set("parameters/Roll/blend_position", input_vector)
animationState.travel("Run")
velocity = velocity.move_toward(input_vector * MAX_SPEED, ACCELERATION * delta)
else:
animationState.travel("Idle")
velocity = velocity.move_toward(Vector2.ZERO, FRICTION * delta)
move()
if input_forward_data["timer"] > 0:
input_forward_data["timer"] -= delta
if input_forward_data["timer"] <= 0:
input_forward_data["taps"] = 0
if Input.is_action_just_pressed("ui_up"):
tatata = "up"
input_forward_data["taps"] += 1
if (input_forward_data["taps"] == 2 and input_forward_data["taps2"] == 0 and input_forward_data["taps3"] == 0 and input_forward_data["taps4"] == 0 and input_forward_data["timer"] > 0.79):
state = ROLL
else:
input_forward_data["taps"] = 1
input_forward_data["taps2"] = 0
input_forward_data["taps3"] = 0
input_forward_data["taps4"] = 0
input_forward_data["timer"] = input_forward_data["reset_time"]
state = MOVE
if input_forward_data["timer"] <= 0:
input_forward_data["timer"] = input_forward_data["reset_time"]
elif Input.is_action_just_pressed("ui_left"):
tatata = "left"
input_forward_data["taps2"] += 1
if (input_forward_data["taps"] == 0 and input_forward_data["taps2"] == 2 and input_forward_data["taps3"] == 0 and input_forward_data["taps4"] == 0 and input_forward_data["timer"] > 0.79):
state = ROLL
else:
input_forward_data["taps"] = 0
input_forward_data["taps2"] = 1
input_forward_data["taps3"] = 0
input_forward_data["taps4"] = 0
input_forward_data["timer"] = input_forward_data["reset_time"]
state = MOVE
if input_forward_data["timer"] <= 0:
input_forward_data["timer"] = input_forward_data["reset_time"]
elif Input.is_action_just_pressed("ui_down"):
tatata = "down"
input_forward_data["taps3"] += 1
if (input_forward_data["taps"] == 0 and input_forward_data["taps2"] == 0 and input_forward_data["taps3"] == 2 and input_forward_data["taps4"] == 0 and input_forward_data["timer"] > 0.79):
state = ROLL
else:
input_forward_data["taps"] = 0
input_forward_data["taps2"] = 0
input_forward_data["taps3"] = 1
input_forward_data["taps4"] = 0
input_forward_data["timer"] = input_forward_data["reset_time"]
state = MOVE
if input_forward_data["timer"] <= 0:
input_forward_data["timer"] = input_forward_data["reset_time"]
elif Input.is_action_just_pressed("ui_right"):
tatata = "right"
input_forward_data["taps4"] += 1
if (input_forward_data["taps"] == 0 and input_forward_data["taps2"] == 0 and input_forward_data["taps3"] == 0 and input_forward_data["taps4"] == 2 and input_forward_data["timer"] > 0.79):
state = ROLL
else:
input_forward_data["taps"] = 0
input_forward_data["taps2"] = 0
input_forward_data["taps3"] = 0
input_forward_data["taps4"] = 1
input_forward_data["timer"] = input_forward_data["reset_time"]
state = MOVE
if input_forward_data["timer"] <= 0:
input_forward_data["timer"] = input_forward_data["reset_time"]
if Input.is_action_just_pressed("attack"):
state = ATTACK
func roll_state(delta):
velocity = roll_vector * ROLL_SPEED
animationState.travel("Roll")
move()
func attack_state(delta):
velocity = Vector2.ZERO
animationState.travel("Attack")
func move():
velocity = move_and_slide(velocity)
func roll_animation_finished():
velocity = velocity * .8
state = MOVE
func attack_animation_finished():
state = MOVE