- Home /
FPS Camera, Camera and Player conflicting...
I didn't want to use the inbuilt script or copy a script from another Answers thread so please don't post a different script, I'd like to figure out the issue so I'm able to learn from it. I've created this script that I placed on my Player (Parent) and Camera (Child), I enable the Y on the Camera and the X on the Player but it seems to be cancelling the Player out.
using UnityEngine;
using System.Collections;
public class PlayerAiming : MonoBehaviour {
[Header("Toggle")]
public bool isX;
public bool isY;
[Header("Sensitivity")]
public float Sensitivity;
private float yRotation;
private float xRotation;
private float curYRotation;
private float curXRotation;
private float yRotationV;
private float xRotationV;
private float Damp=0.1f;
void Update () {
yRotation += Input.GetAxis ("Mouse X") * Sensitivity;
xRotation -= Input.GetAxis("Mouse Y") * Sensitivity;
xRotation = Mathf.Clamp (xRotation, -90, 90);
curXRotation = Mathf.SmoothDamp (curXRotation, xRotation, ref xRotationV, Damp);
curYRotation = Mathf.SmoothDamp (curYRotation, yRotation, ref yRotationV, Damp);
if (isX) {
transform.rotation = Quaternion.Euler (0, yRotation, 0);
}
if (isY) {
transform.rotation = Quaternion.Euler (xRotation, 0, 0);
}
}
}
Answer by Mark Gossage · Jun 08, 2015 at 05:32 AM
Here is how I solved it
Test each script seperately (works ok)
Test both together (fails are reported)
Use the inspector to watch the transform values for the camera (looks suspicious)
Setup the layout to see the game & scene view at the same time (see the player turning, but the camera doesn't)
Change transform.rotation to transform.localRotation
This was a good question with clear problem statement, you just need a little more practice on working though the problem. I hope I gave this to you.
Your answer
Follow this Question
Related Questions
move the object where camera look 0 Answers
Move gameobject pivot 6 Answers
Mobile Camera Movement. 0 Answers
Multiple Cars not working 1 Answer
First Person Character, Mecanim. 1 Answer