#Character Controller - How to keep momentum of previous movement when changing direction?

1 messages · Page 1 of 1 (latest)

crystal vapor
#

Original post for context:

I have a player controlled by a character controller; I want to implement inertia into their movement (so that, when the player changes movement direction, they keep going in the same direction they were going, decelerate while their direction changes, then accelerate normally)
I have already implemented acceleration/deceleration with C#; how can I implement movement changing inertia of the type I described? (Preferably without using a Rigidbody component, as I hear that using one of those with a character controller causes them to conflict with each other or something)

Current character movement code: https://paste.mod.gg/bijgsbmzjymd/0

crystal vapor
#

Update: Analysis of play footage seems to imply that part of the problem is that, when changing direction, the speed from the old direction is fully converted over to the new direction (for example, if you are going forward at 10 u/sec and suddenly move backwards, your velocity doesn't go from 10 u/s to -10 u/sec - it stays at 10 the whole time)
Suggestions on how to properly fix this would be appreciated

bleak cliff
#

Probably the easiest way to do this is use rigid body and apply a force based on input.

#

Since you seem to be implementing velocity manually, you can instead apply an acceleration based on input. You would store a velocity vector and update movement based on that. Then modify that vector based on acceleration calculated from your input.

harsh lotus
#

As hambones already pointed out, you're much better off with just using rigidbody , store the input in update and apply force (in fixed update) in input direction / the direction you want to move in

It will automatically calculate acceleration and deceleration for you

crystal vapor
#

I would prefer to avoid using a rigidbody as I need my player to not roll down gentle slopes and be able to step up onto short steps
In addition, in the future I plan to add a wall-climbing mechanic, and I think that would be very hard to do with a physics-based player

#

@sacred orchid , thoughts? (When you have time, of course)

sacred orchid
#

I've pretty much said all I could say earlier in the main channel.. you basically track the currentVelocity and then manipulate that such as MoveTowards or Lerping torwards a desired Velocity instead.. basically using multiple vectors.. I can't go into a whole lot of detail but i took my working example and chopped it down a bit to maybe help simplify it.. also added some comments to kinda walk thru it.. Example: https://paste.myst.rs/no6c6oli

#

by changing the different dampening/influence rates you can get a few various feelings for the momentum..
i like moderate values as to get snappy input but have a bit of slide once u release the inputs.. the script above does both
when u release completely (no input) it uses the dampenRate but when u change directions it'll use the inputInfluence both modifiers for the MoveTowards/Lerps that are going on

crystal vapor
crystal vapor
#

Good-ish news - I'm not entirely sure what I did, but I think I've made progress
Using the following code:

// Actually move the katamari
if (!Mathf.Approximately(m_CurrentSpeed, 0f))
{
    m_KatamariDirection = Vector3.MoveTowards(m_LastKatamariDirection * m_LastSpeed, m_KatamariDirection * m_CurrentSpeed, m_CurrentMaxSpeed * 20f * Time.deltaTime).normalized;
    m_KatamariCharacter.Move(m_KatamariDirection * m_CurrentSpeed * Time.deltaTime);
}
m_LastSpeed = m_CurrentSpeed;
m_LastKatamariDirection = m_KatamariDirection;

I now have a player that, when it drastically changes direction, will not immediately go in that direction but will slowly swivel around to the input direction while still moving
@sacred orchid Sorry to bother you again, but is that the intended way for your code to work? I don't think it is, but it's such a distinctive effect that I wanted to make sure first

sacred orchid
#

looks similar yea.. its just now bout tweaking values to get what ur after

crystal vapor
#

It's been a few days, so here's what I've been doing
After achieving the effect in the above video (upon changing direction, the player swivels around a point towards the new direction), I decided to work more on this myself since, while this wasn't the behavior I wanted, it was progress(?)
However, it's been several days and I still haven't progressed beyond this point, so I'm asking for help again
I don't want the swivel behavior - I want momentum in my movement
To be specific, I want movement like in this attached video:
https://drive.google.com/file/d/1CCaMAoGB7EZj5TJxd7XMHIvVWb5_ELCO/view
Notice how the player "skids" for a moment when they change direction? That's what I want
Also, here's my current movement function: https://paste.mod.gg/zeqrvuudstkp/0

slender matrix
#

Why are you trying to simulate physics without a rigidbody

#

im confused

cunning grotto
#

@crystal vapor your better off using a rigidbody

cunning grotto
crystal vapor
fiery tide