Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

My character not moving #5

Open
Frostcatzz opened this issue Jul 30, 2021 · 1 comment
Open

My character not moving #5

Frostcatzz opened this issue Jul 30, 2021 · 1 comment

Comments

@Frostcatzz
Copy link

is something wrong with:
extends KinematicBody2D
const MAX_SPEED = 80
const ACCELERATION = 500
const FRICTION = 500

enum {
MOVE,
ROLL,
ATTACK
}

var velocity = Vector2.ZERO
var state = MOVE

onready var animationPlayer = $AnimationPlayer
onready var animationTree = $AnimationTree
onready var animationState = animationTree.get("parameters/playback")

func _ready():
animationTree.active = true

func _physics_process(delta):
match state:
MOVE:
move_state(delta)

	ROLL:
		pass
		
	ATTACK:
		attack_state(delta)
move_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:
	animationTree.set("parameters/idle/blend_position", input_vector)
	animationTree.set("parameters/Run/blend_position", input_vector)
	animationTree.set("parameters/Attack/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)

velocity = move_and_slide(velocity)

if Input.is_action_just_pressed("attack"):
	state = ATTACK

func attack_state(delta):
animationState.travel("Attack")

@ghost
Copy link

ghost commented Mar 1, 2022

did you end up fixing it?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant