Press Z or K to do a barrel roll fox!

This commit is contained in:
Alan Youngblood
2024-11-10 10:59:23 -05:00
parent 7cb72e12cc
commit 307e277eae
3 changed files with 191 additions and 9 deletions

View File

@@ -2,9 +2,11 @@ extends KinematicBody2D
var velocity = Vector2.ZERO
var input_vector = Vector2.ZERO
var roll_vector = Vector2.DOWN
const ACCELERATION = 500
const MAX_SPEED = 80
const ROLL_SPEED = 120
const FRICTION = 500
enum {
@@ -28,7 +30,7 @@ func _process(delta):
move_state(delta)
ROLL:
pass
roll_state(delta)
ATTACK:
attack_state(delta)
@@ -37,9 +39,13 @@ func move_state(delta):
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
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:
@@ -47,19 +53,33 @@ func move_state(delta):
animationState.travel("Idle")
velocity = velocity.move_toward(Vector2.ZERO, FRICTION * delta)
velocity = move_and_slide(velocity)
#velocity = move_and_slide(velocity)
move()
if Input.is_action_just_pressed("roll"):
state = ROLL
if Input.is_action_just_pressed("attack"):
state = ATTACK
func roll_animation_finished():
state = MOVE
func roll_state(delta):
velocity = roll_vector * ROLL_SPEED
animationState.travel("Roll")
move()
func attack_state(delta):
#velocity = Vector2.ZERO
animationTree.set("parameters/Attack/blend_position", input_vector)
animationState.travel("Attack")
#animationTree.set("parameters/Attack/blend_position", input_vector)
velocity = Vector2.ZERO
animationState.travel("Attack")
#velocity = velocity.move_toward(Vector2.ZERO, FRICTION*delta)
#velocity = move_and_slide(velocity)
func move():
velocity = move_and_slide(velocity)
func attack_aninimation_finished():
state = MOVE