Answer the question
In order to leave comments, you need to log in
How to make a character walk and run in Unity?
It is necessary to play the walking animation with this position of the joystick (I have the animation itself). Even in this position, my character slows down, but the walking animation is not enough to play (I also have animation for this):
And in this position, running works and the animation is played.
Animator:
Code PlayerController:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
[RequireComponent(typeof(Rigidbody), typeof (BoxCollider))]
public class PlayerController : MonoBehaviour
{
[SerializeField] private Rigidbody _rigidbody;
[SerializeField] private FixedJoystick _joystick;
[SerializeField] private Animator _animator;
[SerializeField] private float _moveSpeed;
private void FixedUpdate()
{
_rigidbody.velocity = new Vector3(_joystick.Horizontal * _moveSpeed, _rigidbody.velocity.y, _joystick.Vertical * _moveSpeed);
if (_joystick.Horizontal != 0 || _joystick.Vertical != 0)
{
transform.rotation = Quaternion.LookRotation(_rigidbody.velocity);
_animator.SetBool("Move", true);
}
else
_animator.SetBool("Move", false);
}
}
Answer the question
In order to leave comments, you need to log in
Not this way. We need 1d BlendTree with float parameter Speed. At zero the animation is idle, at 0.5 you can walk for variability, and at 1 you can run. The Speed parameter corresponds to the amount of tilt of the joystick, respectively. BlendTree interpolates different animations and can play half run, half walk, or even tiny steps at 10% of the joystick's max. In the latter case, it is important that the idle animation does not contain unnecessary movements, otherwise they will also be mixed.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question