#Struggling with capping velocity for player movement without capping momentum

1 messages · Page 1 of 1 (latest)

mental harbor
#

Sorry for the confusing title but Ive been struggling to make the fundamentals for player movement in a momentum based controller

Im trying to make a snappy and responsive controller to make grounded movement feel precise, but when alot of momentum is applied through an external force (ie air movement which would be alot more faster and floaty), the regrounded movement should become more slippery until your momentum slows back down to the fixed rate

Any ideas or help appreciated and apologies if i havent worded this great

normal shale
#

momentum is proportional to velocity, so if you limit one then you kinda are also limiting the other

mental harbor
#

I think i might be using the wrong terms but I hope i got the point across 😭

rapid flower
#

this is a common problem!

normal shale
rapid flower
#

I'm not sure what the right name is, but you want a variable named something like "stability"

#

it's how in-control the player is

#

when you get whacked, your stability goes down

#

your stability controls how aggressively your velocity is capped (and how quickly you can accelerate)

normal shale
#

(for future reference) maybe try describing your goal in simpler terms, without using specific terminology that you might get wrong (until you get more familiar/confident with said terminology)
not using any term at all is generally better than the wrong term, otherwise it gets confusing lol

rapid flower
#

you can keep the stability low until your velocity gets low enough

upper cloak
#

you can do something like momentum based friction

#

which i guess is kinda like stability

#

So when you are grounded you can measure the horizontal speed that excedes your normal ground speed and reduce the friction while that excess speed exists

#

if im understanding it correctly

mental harbor
#

Ive tried to experiment with the stability idea but how would I go about clamping the players normal ground speed that wouldn’t effect the extra speed upon contacting the ground

#

Like using meaningless numbers to explain

If i want regular groundspeed(just like wasd) to be 1

But air movement to be 2

And upon re entry with the ground it should damp back to 1 with the less stability until its back to the fixed rate of 1

#

Ive played around with linear damping and counter forces but ive just not exactly clicked yet

upper cloak
#

if you clamp the velocity you just destroy any momentum the player has built up

mental harbor
#

Yeah so would it be possible accomplish the precise movement that I want while still leaving the possibility for momentum through other methods

#

Ive tried .AddForce and then applying a -AddForce in the opposite direction but its been iffy idk if theres some advanced physics behind it I just need to click

#

I know I should completely avoid any hard clamps that just set/cap velocity but I still want to have a sort of soft clamp to keep movement precise

#

i could provide some code to try explain im back at my pc but its kinda shit i just keep throwing stuff at the wall to see what sticks

upper cloak
# mental harbor Ive tried .AddForce and then applying a -AddForce in the opposite direction but ...

You dont need a perfect counter force, you need a soft ceiling on player influennce not on velocity
think of ground control like a motor with a top speed, not friction.
you can get precise movement by only accelerating the player toward a fixed target speed and completely stopping player input forces once that speed is reached letting any extra mommentum exist and decay naturally instead of being cancelled

mental harbor
#

thats if im understanding you correctly

#

I think i tried something like turning the movement into an if statement, where if its under the desired speed itll allow input

#

and it worked until like I said I broke the speedcap then my bean just slid across the room

upper cloak
#

but you should never turn input on or off

#

youre only changing its strength/influence

mental harbor
#

well what would the alternative be when trying to cap movement with that threshold?

#

say for example my desired speed was 16, I just stopped adding forces when the speed reached that cap (which i want to be near instant for the precise movement)

upper cloak
#

instead of doing like

if (speed < cap)
    applyInput();
mental harbor
#

itd be alot easier for my wasd to just be a fixed transform or velocity or something but then that shuts off the rest of the physics aspect so i feel stuck between 2 problems

upper cloak
#

you can do something like

float t = speed / cap;        
float inputScale = 1f / (1f + t^2);
applyInput(inputScale);```

this is straight from my own code on something similliar
mental harbor
#

could u explain what the calculation does and what you mean by inputscale?

upper cloak
#

inputscale is the strenght of the input

mental harbor
#

like a force?

upper cloak
#

basically imagine 0 being no control and 1 being full control

#

in better words ig "How strongly the player can push the velocity toward the desired speed"

#

its not a force or a speed itself, its a multiplier applied to your acceleration or steering.

mental harbor
#

sorry im just not able to understand how this helps accomplish the problem, thats probably my bad tho

#

in the simplest terms I think im just trying to make a "fixed" playerspeed that leaves the door open to other physics based forces like momentum at the moment

upper cloak
#

ok let me see if i understand your issue.

1: Ground movement that feels precise and snappy at normal speeds.
2: Momentum from other sources (like air movement) to not be instantly cancelled when you land.
3: Ground control to gradually take over until the player’s speed settles back to the normal ground speed.

Is this correct? is this what you are trying to accomplish?

#

thats what ive gathered from this convo at least

mental harbor
#

yea thats pretty much it so atleast im not useless at getting my point across

#

i still want the player to have some control during problem 3 itd just be slippery or sumn

mental harbor
#

right

upper cloak
#

with what i suggested youre gradually returning control to the player more and more as they get to their normal ground speed

mental harbor
#

well currently i think im stuck on issue 1 where I cant even figure out how to make ground movement feel snappy without using hard velocity clamps

mental harbor
#

Today ive learned i just had to use lerp