I am using New Input System, Starter Asset – Third Person Controller
I wanted to include new input and animations (from Mixamo).
Which I successfully put. However, there is a problem: when I press Z to Sit then moving WASD, the player can move while sitting.
I want player do not move (or disable movement) when doing the animation Sit.
StarterAssetsInputs.cs
[Header("Character Input Values")]
public Vector2 move;
public Vector2 look;
public bool jump;
public bool sprint;
public bool sit; //my input
[Header("Movement Settings")]
public bool analogMovement;
[Header("Mouse Cursor Settings")]
public bool cursorLocked = true;
public bool cursorInputForLook = true;
public bool disableMovement = false; //my input
public void OnSit(InputValue value)
{
SitInput(value.isPressed);
}
public void SitInput(bool newSitInput)
{
if (newSitInput)
{
sit = !sit;
disableMovement = sit;
}
}
ThirdPersonControllers.cs
// animation IDs
private int _animIDSpeed;
private int _animIDGrounded;
private int _animIDJump;
private int _animIDFreeFall;
private int _animIDMotionSpeed;
private int _animIDSit; //my input
ENABLE_INPUT_SYSTEM
private PlayerInput _playerInput;
#endif
private Animator _animator;
private CharacterController _controller;
private StarterAssetsInputs _input;
private GameObject _mainCamera;
private const float _threshold = 0.01f;
private bool _hasAnimator;
private void Update()
{
_hasAnimator = TryGetComponent(out _animator);
JumpAndGravity();
GroundedCheck();
Move();
Sit();
}
private void AssignAnimationIDs()
{
_animIDSpeed = Animator.StringToHash("Speed");
_animIDGrounded = Animator.StringToHash("Grounded");
_animIDJump = Animator.StringToHash("Jump");
_animIDFreeFall = Animator.StringToHash("FreeFall");
_animIDMotionSpeed = Animator.StringToHash("MotionSpeed");
_animIDSit = Animator.StringToHash("Sitting");//my input
}
void Sit()
{
if (_hasAnimator)
{
_animator.SetBool(_animIDSit, _input.sit);
}
}
-
What did I try : I did put the code directly to StarterAssetsInputs.cs and ThirdPersonControllers.cs that already available from Unity Store. I just put my code according to some YT and forum.
-
What were I expecting is… I want player do not move (or disable movement) when doing the animation Sit.
Thank you.
Keltiga is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.