#weird glitch with top down movement

10 messages · Page 1 of 1 (latest)

humble skiff
#

I have some basic top down movement:

    if player.velocity.length() < speed:
        player.velocity += player.input_vector * acceleration
    elif player.velocity.length() > speed:
        player.velocity -= player.input_vector * deceleration
    print(player.velocity)
    player.move_and_slide()

sometimes, when i press 2 inputs at the same time, instead of going diagonally, it doesn't change directions. I know the input vector is working fine though (due to print statements and the animation blendspace working fine)
I have never seen this happen before but I have no idea what im doing wrong

latent moss
#

where is input_vector being set?

#

also, why isn't player handling its own movement?

humble skiff
#

in another script

    input_vector.x = Input.get_axis("left", "right")
    input_vector.y = Input.get_axis("up", "down")
    input_vector = input_vector.normalized()
    if input_vector != Vector2.ZERO:
        last_active_input_vector = input_vector
        animation_tree.set("parameters/Run/blend_position", input_vector)

the player's state machine is handling it

latent moss
#

have you checked that input_vector is correct too?

humble skiff
#

i have

#

through print statements and the fact that the animation blendtree works fine

latent moss
#

that way of setting velocity is probebly causing it. use:

velocity = velocity.move_toward(input_vector, acceleration)
humble skiff
#

that's how i was doing it before but i changed it because i thought that was the problem. it still happens when i do it like that

humble skiff
#

i think i figured it out