Advertisement

Vector calculations for FPS controller

Started by November 06, 2019 11:29 PM
2 comments, last by Lurri90 5 years, 3 months ago

Hey guys I've been trying to wrap my head around this problem hoping someone can help. I am using Unity and using a character controller for the FPS movement script.

So the simplest example of what I'm trying to achieve would be this:

You are running forwards, you jump, do a 180° turn with the mouse and as you land the momentum will push you backwards ( as would happen in the real world ).

OR

You are running forwards, you move the mouse 45° to the left it should feel like the previous direction is slightly pulling you that was as just adjust to the new position.

I can simulate this when only using the keyboard but as soon as I add the mouse things don't feel right. I'm translating the movement vector with the mouse's rotation.

Can anyone offer insight, I can provide code if needed.

Regards!

Lurri.

Sure, I think you want to add the concept of acceleration to your movement. By pressing, forward (or back/strafing) , you want to increase your acceleration vector in the direction of your input. Every frame you add that acceleration to a velocity vector. Then you move your position by that velocity. You also want to add a friction force to your velocity, or it's gonna feel like your character is on ice skates. With this setup, you maintain some momentum, even when you stop movement input.

There are a few different formulas to play around with and variables like acceleration/friction/drag forces to play with to make everything feel tight and right for gameplay. That all depends on your specific game and personal taste for character movement.

Does that help?

-Jawshttp://uploading.com/files/eff2c24d/TGEpre.zip/
Advertisement

Thank you for replying!

Yes you pointed me in the right direction. I basically find a new normalized movement vector every frame when moving which is then  multiplied with acceleration and then multiplied with the player's velocity used for moving.

This topic is closed to new replies.

Advertisement