Hey guys
I have a first person camera system that uses a few animations (mainly for moving the item floating above the camera)
All of the animations have been fine up to now, I have made an animation that moves the camera and for some reason it locks my mouse movement to horizontal only. When I get rid of this animation from the Animator controller it works fine.
Here is how I have my hierarchy: Imgur: The magic of the Internet
The animator: https://imgur.com/Mt8uWbB
And finally here is the code I use for my camera just incase: (I have some animations in a different script due to FixedUpdate causing some delay in the animation)
Could someone try and explain why my cameras movement is locked when I have this animation?
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class CharacterController : MonoBehaviour
{
[SerializeField]
private AudioClip[] clips;
private AudioSource audioSource;
private Animator anim;
public float WalkSpeed = 2.0f;
private bool OnGround;
private bool open;
void Start()
{
audioSource = GetComponent<AudioSource>();
anim = GetComponent<Animator>();
Cursor.visible = false;
Cursor.lockState = CursorLockMode.Locked;
OnGround = false;
open = false;
}
private AudioClip GetRandomClip()
{
return clips[UnityEngine.Random.Range(0, clips.Length)];
}
// Grabs a random clip and plays the sound each time "step" is called.
// "step" has an animation event each time the player models foot touches the ground.
// This means that step is run every time there is an animation event on player animation.
// The player has this on his running and walking animations.
private void Step()
{
AudioClip Step = GetRandomClip();
audioSource.PlayOneShot(Step);
}
void OnCollisionStay(Collision other)
{
if (other.collider.gameObject.CompareTag("Ground"))
{
OnGround = true;
}
}
void OnCollisionExit()
{
OnGround = false;
}
void FixedUpdate()
{
float translation = Input.GetAxis("Vertical") * WalkSpeed;
float strafe = Input.GetAxis("Horizontal") * WalkSpeed;
translation *= Time.deltaTime;
strafe *= Time.deltaTime;
transform.Translate(strafe, 0, translation);
if (OnGround)
{ //movement
if (Input.GetKey("w") || Input.GetKey("a") || Input.GetKey("d"))
{
anim.SetBool("isWalking", true);
anim.SetBool("isJumping", false);
}
else
{
anim.SetBool("isWalking", false);
}
// sprinting
if (Input.GetKey("left shift") && (Input.GetKey("w") && anim.GetBool("isCrouching") == false && anim.GetBool("isCrouchWalk") == false))
{
anim.speed = 1.7f;
WalkSpeed = 3.5f;
if (Input.GetKey("a") || (Input.GetKey("d")))
{
WalkSpeed = 2.5f;
}
}
else
{
anim.speed = 1.0f;
WalkSpeed = 2.0f;
if (Input.GetKey("s"))
{
WalkSpeed = 1.0f;
anim.SetBool("isWalking", true);
}
}
//jump related
if (Input.GetKey("w") && Input.GetKey("space"))
{
anim.SetBool("isWalking", false);
anim.SetBool("isJumping", true);
anim.speed = 1.0f;
}
if (Input.GetKey("w") && Input.GetKey("space") && Input.GetKey("left shift"))
{
anim.SetBool("isWalking", false);
anim.SetBool("isJumping", true);
anim.speed = 1.0f;
}
}
}
}