- Home /
Camera movement doesn't work in Unity (but does in builds)
Hi all,
I've had a nice little third-person character and camera controller system that I made from scratch running in my game for a few days now. Today I added a plane with a gaussian blur shader that is a child of the camera (which is a child of the character) so when the blur is made non-zero, everything the camera sees is blurry! Seems simple enough. And it was! I had a working prototype so I published my changes to the cloud and left Unity for a little bit.
Upon returning, my character simply will not rotate on the horizontal (Y) axis. Not if I restore to the (working!) version I had published a few hours ago, not if I hard-code a non-zero rotation into a script, not if I try to change the Y-rotation in the inspector while the game is running, and definitely not when I use the arrow keys or mouse (the up/down mouse look, however, still functions)! I've tried every debugging trick in my power, including starting from a much earlier and completely functional version and reimplementing the plane in front of the camera. But upon restarting Unity, the same glitch occurs. The worst part: when I build and run my application, there are no issues. Everything works exactly as intended! But obviously this is a significant part of the movement mechanic in my game and it's necessary that the game be playable from within unity as we continue development. Does anyone have any idea what could be going on? I've been spinning my wheels for quite some time now.
Here's the camera controller code (which handles rotating the player):
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class thirdPersonCamera : MonoBehaviour
{
Vector2 mouseLook;
Vector2 smoothV;
public float sensitivity;
public float smoothing;
public GameObject character;
private float spellCastMod;
private firstPersonCharacterControl charObj;
private float rotate;
// Start is called before the first frame update
void Start()
{
charObj = FindObjectOfType<firstPersonCharacterControl>();
character = charObj.gameObject;
rotate = 0;
}
// Update is called once per frame
void Update()
{
if (levelChanger.levelRunning) //conditions for game running
{
Vector2 mouseDelta;
mouseDelta = new Vector2(Input.GetAxisRaw("Mouse X"), Input.GetAxisRaw("Mouse Y"));
if (spellCaster.spellCastWindowActive) spellCastMod = .1f;
else spellCastMod = 1;
mouseDelta *= sensitivity * smoothing * spellCastMod;
smoothV.x = Mathf.Lerp(smoothV.x, mouseDelta.x, 1f / smoothing);
smoothV.y = Mathf.Lerp(smoothV.y, mouseDelta.y, 1f / smoothing);
mouseLook += smoothV;
float x = Input.GetAxis("Horizontal") * charObj.speed * Time.deltaTime;
transform.localRotation = Quaternion.AngleAxis(-mouseLook.y, Vector3.right);
rotate += x * 8;
character.transform.localRotation *= Quaternion.AngleAxis(rotate + mouseLook.x, character.transform.up);
}
}
}
Thank you so much!!