Hey all,
so I’ve been working on my own custom third person character controller using a rigidbody and root motion. I’ve got all the movement and drawing sword mechanics figured out already and working the way I want it to. The part I’m having issues with is getting the jump mechanism to work. I’ve got 3 separate parts of the jump animation (jump start, in air and landing) and none of those have root motion. When I apply addforce to my rigidbody, during the in air animation the character only goes up and down in the Y axis but ignores the velocity in the horizontal direction. What I am trying to do is to go from a running animation into a jump animation and be able to adjust the height of the jump kind of like the third person controller in the starter assets
I’ve come to the conclusion that I need to apply a velocity based on the input and velocity of the rigidbody before the jump to the inplace animations. I have code that checks whether the character is grounded or not but what I don’t know is how to script a velocity based on the input onto the jump animations while the rigidbody is not grounded.
I’m using onAnimatorMove to apply the root motion through code to the other locomotion animations so I’m wondering if I need to code something in there to apply a velocity/rootmotion to the jump animations. Essentially what I need is a bit of extra code to apply the horizontal motion/velocity to the character while it is not grounded. Any help would be appreciated on how I would code something like that.
private void OnAnimatorMove()
{
m_animator.ApplyBuiltinRootMotion();
if (Grounded && Time.deltaTime > 0)
{
Vector3 v = (m_animator.deltaPosition * 1) / Time.deltaTime;
v.y = m_rigidbody.velocity.y;
m_rigidbody.velocity = v;
if (isSpaceKeyPressed)
{
m_rigidbody.AddForce(Vector3.up * _verticalVelocity, ForceMode.Impulse);
}
}
}