#Character animation blending

1 messages · Page 1 of 1 (latest)

random sail
#

Your blend tree needs to be more complicated

#

Kidding of course, but there are a few things I would recommend

#

First, to solve your smoothing issue, you need to accelerate your character up to speed

#

The animation is directly tied to the speed of your character, if your character velocity snaps from (0, 0, 0) to (0, 0, 1) then your animation will also snap

indigo void
#

like that but in blend tree

random sail
#

Well, you will have to use a separate parameter that smoothly increases to your current speed

indigo void
#

but i havent smooth movement

random sail
#

speedParameter = Mathf.MoveTowards(speedParameter, moveSpeed, Time.deltaTime)

indigo void
random sail
#

I recommend you smooth the actual player movement instead though

indigo void
#

im just set animation values based on input

random sail
#

Alright, well you need to smooth the values

random sail
#

Paste the code and I'll show you

indigo void
#
  public void Update()
    {
        if (!isLocalPlayer) return;
        UpdateAnimatorProperties();
    }

 private void UpdateAnimatorProperties()
    {
        var movementInput = Inputs.Player.Movement.ReadValue<Vector2>();
        if (IsRunning)
            movementInput *= 2;

        Animator.SetBool("IsInAir", IsJumping);
        Animator.SetFloat("MovementX", movementInput.x, .1f, Time.deltaTime);
        Animator.SetFloat("MovementZ", movementInput.y, .1f, Time.deltaTime);
    }

#

its mirror NetworkBehaviour tho im using isLocalPlayer

#

public void FixedUpdate()
    {
        if (!isLocalPlayer) return;
        ApplyGravity();
        HandleMovement();
        HandleRotation();
    }
private void HandleMovement()
    {
        var movementInput = Inputs.Player.Movement.ReadValue<Vector2>();
        var moveDirection = transform.forward * movementInput.y + transform.right * movementInput.x;// new Vector3(movementInput.x, 0, movementInput.y);

        var deltaMove = moveDirection * (IsRunning ? RunSpeed : WalkSpeed);

        if (CharacterController.isGrounded) IsJumping = false;

        if (Inputs.Player.Jump.ReadValue<float>() > .5f && CharacterController.isGrounded)
        {
            deltaMove.y += CurrentJumpVelocity = JumpVelocity;
            IsJumping = true;
            Animator.SetTrigger("Jump");
        }

        if (IsJumping)
        {
            CurrentJumpVelocity -= Gravity * Time.deltaTime;
            deltaMove.y += CurrentJumpVelocity;
        }

        CharacterController.Move(deltaMove * Time.deltaTime);
    }

also movement

random sail
#
    public float acceleration = 5f;
    Vector2 playerVelocity = Vector2.zero;
    private void UpdateAnimatorProperties()
    {
        var movementInput = Inputs.Player.Movement.ReadValue<Vector2>();
        if (IsRunning)
            movementInput *= 2;

        playerVelocity = Vector2.MoveTowards(playerVelocity, movementInput, acceleration * Time.deltaTime);

        Animator.SetBool("IsInAir", IsJumping);
        Animator.SetFloat("MovementX", playerVelocity.x, .1f, Time.deltaTime);
        Animator.SetFloat("MovementZ", playerVelocity.y, .1f, Time.deltaTime);
    }```
#

Here I added playerVelocity and acceleration

#

Instead of feeding movementInput into your parameters directly, it instead changes playerVelocity per frame

#

playerVelocity is then what we feed into your parameters

indigo void
#
playerVelocity = Vector2.MoveTowards(playerVelocity, movementInput, acceleration * Time.deltaTime);

why?
probably

playerVelocity = Vector2.MoveTowards(playerVelocity, movementInput * acceleration ,  Time.deltaTime);

?

random sail
#

No

#

The second parameter of MoveTowards represents the max speed

#

The third parameter represents how fast playerVelocity approaches max speed, the acceleration

indigo void
#

ehhh

#

how i can made curve for that?

#

like start action more quicly and stop it more quicy

#

@random sail tho with simple float accelerations it looks a bit better

#
private void UpdateAnimatorProperties()
    {
        var targetAnimationVelocity = Inputs.Player.Movement.ReadValue<Vector2>();

        if (IsRunning)
            targetAnimationVelocity *= 2;

        MovementAnimationVelocity = 
            Vector2.MoveTowards(MovementAnimationVelocity, targetAnimationVelocity, Time.deltaTime * MovementAnimationVelocityMultiplier);

        Animator.SetBool("IsInAir", IsJumping);
        Animator.SetFloat("MovementX", MovementAnimationVelocity.x, .1f, Time.deltaTime);
        Animator.SetFloat("MovementZ", MovementAnimationVelocity.y, .1f, Time.deltaTime);
    }
random sail
#

Move your character using MovementAnimationVelocity

#

Then your animation matches the speed

random sail
#

Tell me how you're moving your character

indigo void
#

also its probably bad idea (cuz it must be shooter)

indigo void
# random sail Tell me how you're moving your character
 private void HandleMovement()
    {
        var movementInput = Inputs.Player.Movement.ReadValue<Vector2>();
        var moveDirection = transform.forward * movementInput.y + transform.right * movementInput.x;// new Vector3(movementInput.x, 0, movementInput.y);

        var deltaMove = moveDirection * (IsRunning ? RunSpeed : WalkSpeed);

        if (CharacterController.isGrounded) IsJumping = false;

        if (Inputs.Player.Jump.ReadValue<float>() > .5f && CharacterController.isGrounded)
        {
            deltaMove.y += CurrentJumpVelocity = JumpVelocity;
            IsJumping = true;
            Animator.SetTrigger("Jump");
        }

        if (IsJumping)
        {
            CurrentJumpVelocity -= Gravity * Time.deltaTime;
            deltaMove.y += CurrentJumpVelocity;
        }

        CharacterController.Move(deltaMove * Time.deltaTime);
    }
random sail
#
public float acceleration = 5;
Vector3 playerVelocity;
private void HandleMovement()
    {
        var movementInput = Inputs.Player.Movement.ReadValue<Vector2>();
        var moveDirection = transform.TransformDirection(new Vector3(movementInput.x, 0, movementInput.y));
        var deltaMove = moveDirection * (IsRunning ? RunSpeed : WalkSpeed);

        if (CharacterController.isGrounded) IsJumping = false;

        if (Inputs.Player.Jump.ReadValue<float>() > .5f && CharacterController.isGrounded)
        {
            deltaMove.y += CurrentJumpVelocity = JumpVelocity;
            IsJumping = true;
            Animator.SetTrigger("Jump");
        }

        if (IsJumping)
        {
            CurrentJumpVelocity -= Gravity * Time.deltaTime;
            deltaMove.y += CurrentJumpVelocity;
        }
        
        playerVelocity = Vector3.MoveTowards(playerVelocity, moveDirection, acceleration * Time.deltaTime);
        CharacterController.Move(playerVelocity * Time.deltaTime);
    }