- Home /
Question by
TheNostWest · Aug 05, 2019 at 02:18 PM ·
animationanimatorbugblender animationblend tree
Help!Bug with animation blend.When I press the opposite buttons almost simultaneously (A + D or W + S) my animation is buggy
private void Update() {
if (Input.GetKeyDown(KeyCode.LeftControl))
{
m_IsCrouch = !m_IsCrouch;
}
if (m_IsCrouch)
{
m_CharacterController.height = 1f;
m_WalkSpeed = 2f;
m_RunSpeed = 3f;
m_JumpSpeed = 3f;
}
if(!m_IsCrouch)
{
m_CharacterController.height = m_CharacterController.height + 0.1f;
m_WalkSpeed = 4f;
m_RunSpeed = 6f;
m_JumpSpeed = 6f;
}
if (m_CharacterController.height >= 1.8f)
{
m_CharacterController.height = 1.8f;
}
if (m_CharacterController.isGrounded)
{
if (Input.GetButton("Jump")) {
animator.SetBool("JumpWithRifle", true);
}
else
{
animator.SetBool("JumpWithRifle", false);
}
}
if (m_IsWalking ==false)
{
animator.SetBool("RunWithRifle", true);
animatorFoot.SetBool("RunWithRifle", true);
}
else
{
animator.SetBool("RunWithRifle", false);
animatorFoot.SetBool("RunWithRifle", false);
}
horizontal = Input.GetAxis ("Horizontal");
vertical = Input.GetAxis ("Vertical");
RotateView();
if (!m_Jump)
{
m_Jump = CrossPlatformInputManager.GetButtonDown("Jump");
}
if (!m_PreviouslyGrounded && m_CharacterController.isGrounded)
{
StartCoroutine(m_JumpBob.DoBobCycle());
PlayLandingSound();
m_MoveDir.y = 0f;
m_Jumping = false;
}
if (!m_CharacterController.isGrounded && !m_Jumping && m_PreviouslyGrounded)
{
m_MoveDir.y = 0f;
}
m_PreviouslyGrounded = m_CharacterController.isGrounded;
}
public void PlayAnim(float horizontal, float vertical)
{
animator.SetFloat("Horizontal", horizontal);
animator.SetFloat("Vertical", vertical);
animatorFoot.SetFloat("Horizontal", horizontal);
animatorFoot.SetFloat("Vertical", vertical);
}
private void PlayLandingSound()
{
m_AudioSource.Play();
m_NextStep = m_StepCycle + .5f;
}
private void FixedUpdate()
{
float speed;
GetInput(out speed);
Vector3 desiredMove = transform.forward*m_Input.y + transform.right*m_Input.x;
RaycastHit hitInfo;
Physics.SphereCast(transform.position, m_CharacterController.radius, Vector3.down, out hitInfo,
m_CharacterController.height/2f, Physics.AllLayers, QueryTriggerInteraction.Ignore);
desiredMove = Vector3.ProjectOnPlane(desiredMove, hitInfo.normal).normalized;
m_MoveDir.x = desiredMove.x*speed;
m_MoveDir.z = desiredMove.z*speed;
if (m_CharacterController.isGrounded)
{
m_MoveDir.y = -m_StickToGroundForce;
PlayAnim(horizontal,vertical);
if (m_Jump)
{
m_MoveDir.y = m_JumpSpeed;
PlayJumpSound();
m_Jump = false;
m_Jumping = true;
}
}
else
{
m_MoveDir += Physics.gravity*m_GravityMultiplier*Time.fixedDeltaTime;
}
m_CollisionFlags = m_CharacterController.Move(m_MoveDir*Time.fixedDeltaTime);
ProgressStepCycle(speed);
UpdateCameraPosition(speed);
m_MouseLook.UpdateCursorLock();
}
private void PlayJumpSound()
{
m_AudioSource.Play();
}
private void ProgressStepCycle(float speed)
{
if (m_CharacterController.velocity.sqrMagnitude > 0 && (m_Input.x != 0 || m_Input.y != 0))
{
m_StepCycle += (m_CharacterController.velocity.magnitude + (speed*(m_IsWalking ? 1f : m_RunstepLenghten)))*
Time.fixedDeltaTime;
}
if (!(m_StepCycle > m_NextStep))
{
return;
}
m_NextStep = m_StepCycle + m_StepInterval;
PlayFootStepAudio();
}
Comment