UpdateAnimator() issue when using controller

I’ve implemented the UpdateAnimator() the way shown in the video but noticed that it didn’t work well when using the controller.
That is because my controller outputs some small value instead of 0 when using the stick. i.e. (when moving the stick to the right the InputReader.MovementValue is (x:1, y:0.1)).

I got around that by getting rid of the conditional statements and just feeding the MovementValue directly to the SetFloat() like so

stateMachine.Animator.SetFloat(TargetingForwardHash, stateMachine.InputReader.MovementValue.y, 0.1f, deltaTime);
stateMachine.Animator.SetFloat(TargetingRightHash, stateMachine.InputReader.MovementValue.x, 0.1f, deltaTime);

Why not go for this approach instead?
Is there some downside going forwards?

None that I can see. As long as the end result gives you footsteps that match up to the movement of the character, you’re good to go.

1 Like

The problem with using the approach you wrote is that the animation might look slow like your character is walkin on the moon, this is because the small values you mention. The reason it looks good for the instructor is that he is using either -1 or 1 so the animation runs or blends completely instead of looking slow.

What I did to avoid this when using a gamepad was to define a dead zone value for the joysticks. In my case I wrote that if the value was less than 0.25f to take it as 0 but anything above it would be either 1 or -1 depending on its sign

float forward = Mathf.Abs(stateMachine.InputHandler.MovementValue.y) < 0.25f ? 0f : Mathf.Sign(stateMachine.InputHandler.MovementValue.y);
float right = Mathf.Abs(stateMachine.InputHandler.MovementValue.x) < 0.25f ? 0f : Mathf.Sign(stateMachine.InputHandler.MovementValue.x) ;
4 Likes

This topic was automatically closed 24 hours after the last reply. New replies are no longer allowed.

Privacy & Terms