#Character keeps sliding randomly
1 messages · Page 1 of 1 (latest)
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
also printed out the moment this happens, large number is velocity and the smaller ones is direction
when its good it does this
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?
both directions this happens
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
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
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
well i did not dash in any of these situations, but i can try adding another else i guess??
wait thatd not work
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.
im guessing id need to add the whole thing in a paste bin?
discord lets you send big stuff as files
hope this works
forgive me if i did it wrong or if the code is kinda bad
maybe i should just rewrite the acceleration and desacceleration lol
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.
well, the idea was that they sped up and once they reached max speed they stopped
(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