armedunity.com uses cookies to improve user experience.

By continuing to use this site, you agree to allow us to store cookies on your computer.

• 0

# Disabling Input Movement in Midair While Keeping Strafing

## Question

Hey guys,

So I am currently using a script where the main movement part goes as follow:

Then, there are then acceleration force applied depending if the player is on the ground or in the air but this still gets called while in the air.

My issue is that while the overall movement is fine both in the air and on the ground and provides the right results except one thing,

You are able to move left, right up and down in midair while we would just want it to be strafing motions (curve only) so you can't explicitly press A and go Right or D and go left (same goes for forward and back).

TLDR: Keeping movement the same while preventing the player from moving manually without any residual accel without strafing in midair.

Edited by jesusisafriendof

## Recommended Posts

• 1

Ya that makes more sense. If your in air movement is fine the way it is, you could just bind it's x and z velocity values using Mathf.Clamp. Something like:

x = Mathf.Clamp(x, velocityAtJumpTime - range, velocityAtJumpTime + range);

Or you can simply increment by a very small number instead using =, something like:

if(!grounded) x += Input.GetAxis("Horizontal") * someInsanelySmallValue;

//clamp x like before

##### Share on other sites

• 0

Sounds like your overcomplicating the question and math behind it. Are you asking how to keep in air movement but make the force provided by the input gradual instead of sudden? Or you wanting to elimate in air movement and maintain it's base velocity? I guess you would have to give some kind of example because I don't really get exactly what your wanting

##### Share on other sites
• 0

Maybe I am, been butting my head against this for about a week now. So basically I want to keep air movement as is while limiting the effect of x.input and y.input while in midair to absolute velocity (in whatever direction) so that in if you just jump then press A you just very slightly move to the right then stop or not at all, does this make more sense?

If this dosen't work I will try to find an example of this but this would be very similar to how it's handled in the source engine. You can't just "move" in midair yet you can bunnyhop and such (which is already possible with the rest of my code).

Edited by jesusisafriendof

##### Share on other sites
• 0

Always clamp if you increment tho, even if you clamp to the max velocity, because you never want your player to move faster than max velocity obviously

##### Share on other sites
• 0

I will experiment with this after my class and report back and I found an example, so in this game if you jump and spam/hold movement key you can slightly wiggle (left/right forward/backwards) but that's it, like if you input had a limited effect  but at the same time he's able to move this way in midair:

In my code I'm pretty much already able to move this way in midair BUT at the same time using movement key without strafing also moves you.

Is that what you understood?

Edited by jesusisafriendof

##### Share on other sites
• 0

Yes, you said that you already have in air movement tho so you should be able to allow in air movement if strafing = true, else movement = 0, gravity, 0

##### Share on other sites
• 0

Okay thanks, yeah I do have the same one ultimately controlling both and it wasnt getting called in a if loop for some reason but I will get it to work, thanks!

## Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

×   Pasted as rich text.   Paste as plain text instead

Only 75 emoji are allowed.