+1 vote

Basically, This problem have been really, really confusing and frustrating.
So I made a code so my character uses animations when using different keys on the keyboard.
BUUUUT it somehow made my character even faster and im like ?????
Here's my code for the character:

extends KinematicBody2D
#Variables and stuff

const Friction = 500

var Velocity = Vector2.ZERO

const MAX_SPEED = 80

onready var animationPlayer = $AnimationPlayer

enum{
    MOVE,
    ROLL,
    ATTACK
}

var State = MOVE

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

func _ready():
    animationTree.active = true

func _physics_process(delta):
    match State:

        ROLL:
            pass

        ATTACK:

            attack_state(delta)

        MOVE:
            move_state(delta)
    move_state(delta)





func move_state(delta):
        #Movement Inputs
    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()

    #Thing that actually do the Movement

    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, Friction * delta)
    else:
        animationState.travel("Idle")
        #Complicated Meeeeeethsss

        Velocity = Velocity.move_toward(Vector2.ZERO, Friction * delta)
    Velocity = move_and_slide(Velocity)
    if Input.is_action_pressed("attack"):
        State = ATTACK
    pass
func attack_state(delta):
    animationState.travel("Attack")
    pass

Any help would be greatly appreciated. Thanks in advance.

in Engine by (32 points)

1 Answer

+2 votes
Best answer

Without a detailed look at the posted code, I notice that you're likely calling move_state(delta) twice from _physics_process - once from inside the match when the state is MOVE and once at the bottom of the function.

I assume that double-call is leading your statement of made my character even faster (??)

by (21,864 points)
selected by

Omfg how did I not realize this..
Thank you good sir, Was stuck on this for awhile lol
Have an absolutely fantastic day!

Welcome to Godot Engine Q&A, where you can ask questions and receive answers from other members of the community.

Please make sure to read Frequently asked questions and How to use this Q&A? before posting your first questions.
Social login is currently unavailable. If you've previously logged in with a Facebook or GitHub account, use the I forgot my password link in the login box to set a password for your account. If you still can't access your account, send an email to [email protected] with your username.