Avindr / MxM-IssueTracking

7 stars 0 forks source link

Possible gravity bug in root motion applicator #155

Closed andthenwhat closed 2 years ago

andthenwhat commented 2 years ago

MxMRootMotionApplicator.cs:119 is currently

                        moveDelta.y = (m_charController.Velocity.y +
                            Physics.gravity.y * a_deltaTime) * a_deltaTime;

but I think I think velocity.y needs to be scaled by a_deltaTime as well (since velocity is in m/s):

                        moveDelta.y = (m_charController.Velocity.y*a_deltaTime +
                            Physics.gravity.y * a_deltaTime) * a_deltaTime;

the player was dropping like a rock whenever I went off a platform, and I think the latter is right. I searched issues and discord for references to this and didn't see any, but apologies if this is a duplicate.

Avindr commented 2 years ago

So Velocity it m/s, Acceleration is m/s^2 (i.e. gravity)

So in the brackets we only multiply the acceleration by delta time to turn it into a velocity increment so that we can add it to the current velocity.

New Velocity = m/s + (m/s^2 * s) = m/s + m/s = m/s

Then we multiply the New Velocity by delta time again to get the displacement: m/s * s = m

So after looking at it, the first one does seem correct to me still unless I've missed something. However, if the character is dropping like a rock there must be some other issue which I haven't seen myself. I'll investigate.

andthenwhat commented 2 years ago

My fault for not seeing the parentheses around velocity, sorry for wasting your time!