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.
#Velocity.x and walking speed conflicting(Solved)
1 messages · Page 1 of 1 (latest)
Velocity.x and walking speed conflicting(unsolved)
use Vector2.limit_length() to enforce a speed limit.
use it every time before calling move_and_slide()
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
put the velocity to add on a separate variable and limit that instead. THEN add it to the actual velocity before using it.
that makes sense, except if i do a basic "velocity.x += walking _var" it would recursively increase velocity.x
i mean, is that not the point?
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.
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)
i could remove the limit entirely too so that it doent walk when over its speed.
i need to be right back
generally, i enforce speed limits by adding drag.
like Celeste
just decrease velocity by velocity * dragMod
where dragMod is a value between 0 and 1
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
^
but if you could go more into depth on the drag i would greatly appreciate that
you can also shorthand it to velocity *= dragMod
what you are doing here is saying "decrease velocity by a fraction of itself"
so the faster it goes, the higher the decrease.
this essentially means diminishing returns on acceleration.