#Velocity.x and walking speed conflicting(Solved)

1 messages · Page 1 of 1 (latest)

blazing elbow
#

my walking needs to be limited to a certain speed so i dont walk too fast. but i have movement that requires me to go OVER that max speed. for example if i have 1000 velocity.x moving right, but i press right to go that direction and my max walking speed is only 500, my speed will go from 1000 to 500, when it should be adding 500 to go 1500.

#

i can provide more info if needed.

blazing elbow
#

Velocity.x and walking speed conflicting(unsolved)

burnt silo
#

use Vector2.limit_length() to enforce a speed limit.
use it every time before calling move_and_slide()

blazing elbow
#

i dont want to add a speed limit to the velocity vector, just i want to add a limit to the velocity i add when i walk in a certain dir with out it limiting other factors affecting my vel

burnt silo
#

put the velocity to add on a separate variable and limit that instead. THEN add it to the actual velocity before using it.

blazing elbow
#

that makes sense, except if i do a basic "velocity.x += walking _var" it would recursively increase velocity.x

burnt silo
#

i mean, is that not the point?

blazing elbow
#

well velocity.x would be constantly increasing. lets say velocity.x is 100, and walking var is 200, velocity would the equal 300, but it keeps getting added to be 500, 700 , 900 ect.

burnt silo
#

maybe you can just move_toward() the walk velocity?
if you need more velocities, you can sum them.

#

or make the walk velocity account for the actual velocity. like walkVel = (velocity + walkVel).limit_length(walkVel)

blazing elbow
#

i could remove the limit entirely too so that it doent walk when over its speed.

#

i need to be right back

burnt silo
#

generally, i enforce speed limits by adding drag.
like Celeste

blazing elbow
#

ok good to note

#

just not sure how i would do that

burnt silo
#

just decrease velocity by velocity * dragMod
where dragMod is a value between 0 and 1

blazing elbow
#

ooohhhhh

#

alr lemme get back to you, thanks for the help tho!

blazing elbow
#

so i just got rid of the limiters for the x velocity, this does make it inconsistent but it is negligible (if speed is 30 and max speed is 500 it has a range from 500 - 530) This techincally does mkae it have an inconsistent max speed but it works great when applied to movement because it naturally stops it self

blazing elbow
#

but if you could go more into depth on the drag i would greatly appreciate that

burnt silo
#

you can also shorthand it to velocity *= dragMod

burnt silo
blazing elbow
#

ok

#

the getting rid of max speed doesnt work well with decel, but drag sounds like a great idea, lemme mess around with it and see what i can do