#61 - Unity Character Jump Leg based on motion

Date: 2019-05-18 12:00 - c#

Simple snippet of code to chose a jump leg for character animator based on the angle of motion.

public void PerformJump() {
    character.Velocity.y = JumpVelocity;
    character.IsGrounded = false;

    float angle = -Vector3.Dot(character.Motion.normalized, character.transform.right);
    float jumpLeg = Mathf.Abs(angle) > 0.1 ? angle : UnityEngine.Random.Range(-1.0f, 1.0f);
    character.Animator.SetFloat("JumpLeg", Mathf.Sign(jumpLeg));
}

Previous snippet | Next snippet