#Character keeps sliding randomly

1 messages · Page 1 of 1 (latest)

tall summit
#

my character keeps drifting randomly and idk why, anyone know why it happens?
first part is how it should be happening and second part is how it should not

steady relic
#

Share your movement code please!

#

I'm guessing it's something to do with how you're slowing your player down/applying friction but it's not immediately obvious just from looking

tall summit
#

also printed out the moment this happens, large number is velocity and the smaller ones is direction

#

when its good it does this

steady relic
#

Is this a problem that exclusively happens when your character moves to the right? Or can it also happen when they move to the left?

steady relic
#

could you share the entire class?

#

there's nothing in the function you shared that I think would cause this

#

but it's possible whatever is calling it is doing it incorrectly

tall summit
#

ok well, i experimented a bit
if i remove this the character slides endlessly

im guessing when i press a key to change directions, its as if this is not affecting the charater, causing them to drift

steady relic
#

well yeah but you derive that from input, so either the character should be moving (it's nonzero) or they should be stopping (it's zero). Some kind of in-between state isn't possible because it's a boolean.

It's possible it's something to do with the dash state?

#

because you only trigger your stopping behavior if you're not dashing

tall summit
#

well i did not dash in any of these situations, but i can try adding another else i guess??

#

wait thatd not work

steady relic
#

it's why I'm asking to see the rest of the class, I'm wondering if wherever you're calling run has some kind of conditional that could be affecting the behavior. 'cuz I noticed move_and_slide is absent from the function which your CharacterBody2D needs to move.

tall summit
#

im guessing id need to add the whole thing in a paste bin?

steady relic
#

discord lets you send big stuff as files

tall summit
#

forgive me if i did it wrong or if the code is kinda bad

#

maybe i should just rewrite the acceleration and desacceleration lol

steady relic
#

I'm not here to judge your code :P just to help

#

Are you... Applying friction anywhere else? I ask because on line 85,

velocity.x += horizontal_direction * speed * delta

this would apply unlimited acceleration and cause your character to speed up forever and ever, not achieve a constant speed.

tall summit
#

(stopped speeding up that is)

#

i ended up rewriting the code with someone else's snippet as reference, i think it solved the issue

#

code is much shorter now too