0

How best to handle Character Controller acceleration with an Animation Curve?

Victory Over All 1 year ago updated 1 year ago 0

I have a bit of a long question for hopefully a simple problem, so please bear with me!

I've been building a first person controller using CharacterController.Move (not rigidbody and physics). I was wondering, what might be the "correct" or best way to implement acceleration up to a desired speed where the acceleration can be adjusted by an animation curve? I've been using curves for jumping and mouse look, and it's a great way to have control over the feel of the controller.

My movement is set up quite simply (see attached image below, you might need to zoom or open in a new tab to see it clearly) where I multiply the x+z input axis by a Movement Speed variable, and use a MoveTowards unit to retain some of the resulting movement and reduce control when in the air. I also use a MoveTowards so my Movement Speed variable changes smoothly when switching between walk and sprint speeds (my Target Movement Speed variable). I was thinking of doing something like evaluating an animation curve with the current horizontal speed (Magnitude of x+z of CharacterController.Velocity) as "t", and multiplying the result by my Target Movement Speed variable to get a new Movement Speed.

But something about this approach doesn't feel right to me... I've seen a few calculations online like "Speed = Speed - (Acceleration * Time.DeltaTime)" but I'm not sure how I'd implement this with an animation curve to control the rate of acceleration. Anyone else tackled this before or have any ideas?

Thanks!

P.S. I'm guessing the current horizontal speed needs to be included in the equation somehow as otherwise, for example, the character's movement direction would "accelerate" even when walking into a wall, and upon jumping over that wall the character would launch over it at max speed... hmmm. Food for thought there!

Bolt Version:
Unity Version:
Platform(s):
Scripting Backend:
.NET Version (API Compatibility Level):