cant figure out how to smooth my camera

ok. i normally post in here as a last resort…

i have been dealing with this problem for close to 2 months now. i have tried nearly every possible combination of code suggested to me.

my camera is attached to my head, which is rigged to my character. this is only in first person view.

when i walk forward, the screen swings from side to side. now i understand why it is doing this, but what i dont understand is how to fix it.

heres the code with some combinations you can see commented out that ive already tried:

if (firstPersonView == true Input.GetKey(KeyCode.W) !Input.GetKey(KeyCode.LeftAlt) getInVehicle.inDriver == false getInVehicle.inRover == false getInVehicle.inShuttle == false) {

headBounceSensitivity = .1;
// cam.transform.LookAt(lookBox);
//cam.transform.parent = null;
//cam.transform.position = camParent.transform.position;
//cam.transform.position.y += .1;
//camParent = transform.root;
//var rotation = Quaternion.Euler(0, 30, 0);
//cam.transform.localEulerAngles.y = 0;
//cam.transform.Rotate ( 0, - (cam.transform.localEulerAngles.y), 0);
//var mank = target1.localEulerAngles
//cam.transform.eulerAngles = new Vector3(cam.transform.eulerAngles.x, target1.transform.eulerAngles.y, cam.transform.eulerAngles.z);
///var dickson = cam.transform.localEulerAngles.y ;
//cam.transform.Rotate (0, dickson, 0);
//transform.localRotation = Quaternion.identity;
//localEulerAngles = new Vector3(-rotationY, rotationX, 0);

thePosition = cam.transform.eulerAngles.y;
endPosition = 0.0;
cam.transform.eulerAngles = Vector3(0, Mathf.Lerp(thePosition, endPosition, 1.0), 0);

//cam.transform.localEulerAngles.y = Mathf.Lerp (cam.transform.localEulerAngles.y, 0.0, 0.02);

//cam.transform.localEulerAngles.y = 0;
Debug.Log ("cam local euler y is " + cam.transform.localEulerAngles.y);
//cam.transform.rotation = ( cam.transform.rotation.x, 0, cam.transform.rotation.z);

//cam.transform.localEulerAngles = Vector3(0.0, 0.0, 0.0);

//thePosition = transform.TransformPoint(0.0, 0.0, 12.0);
//cam.transform.LookAt (thePosition);
//wantedRotationAngle = 0.0;

//currentRotationAngle = transform.eulerAngles.y;

// Damp the rotation around the y-axis
//currentRotationAngle = Mathf.LerpAngle (currentRotationAngle, wantedRotationAngle, 0);

//currentRotation = Quaternion.Euler (0, 0, 0);
//cam.transform.rotation = currentRotation;
cam.transform.localRotation = Quaternion.Euler(0,0,0);
//var target = Quaternion(0.0, 0.0, 0.0, 0.0);

//cam.transform.rotation = Quaternion.Slerp(cam.transform.rotation, target, .01);

//Debug.Log ("camparent Local euler y is " + camParent.transform.localEulerAngles.y);
//Debug.Log ("camparent Global euler y is " + camParent.transform.eulerAngles.y);
//Debug.Log ("cam Global euler y is " + cam.transform.eulerAngles.y);
//Debug.Log ("cam local euler y is " + cam.transform.localEulerAngles.y);

}

i figured if i just made the cam.transform.rotation.y = 0 that would work but has no success.
ive also tried these lerps, slerps, berpz on fixed update, late update, with different time.time, time.delta time. .01, 0.0, 0.02, etc etc
please help!!!

GoonCorp

So you want your character’s animation to dictate the camera’s position but not it’s rotation?

camera.transform.rotation = characterController.rotation;
camera.transform.Rotate( Vector3( upDownRotation, 0, 0 ) );

Side note - Quaternions are not understandable (unless you have so much Maths Goodness that you already know what they are). Stick to using Quaternion class functions, and transform.Rotate* functions. Don’t directly edit x/y/z/w values of Quaternions.

Hello GoonCorp.

I suggest you remove most of the commented code since it mostly makes it harder to read the actual code.
Also, could you describe in detail what it is you want to achieve with this script?
Lastly I suggest that you put the code in code brackets. [ CODE ] Write your code here [ / CODE ] (without spaces).

As for the problem: since I’m not sure what you want the end result to look like I can’t say for sure. Maybe try to have the camera only follow the head in cerntain axis? (for example, maybe ignore the rotation in z-axis).

Edit: I saw that you had tried to make the transform.rotation.y = 0. If that doesn’t work, it could be because the animation plays after? Try: instead of having the camera attached to the head, have to just following the head and make it copy the rotation of the head. (for example. copy all axis except the y-axis)

Sincerely
Lime_x

thanks for the responses it helped.