- Home /
Camera following Pivot not working
I want to make a thirdpersonshooter-camerascript
the player is the parent of an empty(pivot) and the camera should follow the pivot
when i move my mouse to the left the player rotates to the left with the pivot but the problem lies with the camera:
it keeps the distance to the pivot but it doesnt inherit the rotation
(red is how the camera is, green is how the camera should be)
following the responsible part of the cameracontroller:
//rotation of the camera
transform.position = pivot.transform.position + (pivot.transform.rotation * (new Vector3 (0.5f,2,-2)));
targetlook = Quaternion.LookRotation (pivot.transform.position - transform.position);
transform.rotation = Quaternion.Slerp (transform.rotation, targetlook, smoothlook * Time.deltaTime);
transform.LookAt (pivot.transform);
any advice?
Answer by Runalotski · Aug 02, 2015 at 03:02 PM
make a new empty game object and call it pivot and then child it to the character
now make the camera a child of the pivot object,
now make a script that makes the pivot rotate with mouse movement and attach it to the pivot game object
you can the camera any distance and starting rotation you like it will rotate around the pivot game object.
i did that but as long as this piece of code is active its the same case as above:
xRotation -= Input.GetAxis ("$$anonymous$$ouse Y") * mousespeed;
xRotation = $$anonymous$$athf.Clamp (xRotation,-110,110);
transform.rotation = Quaternion.Euler (xRotation,0,0);
Dont set the rotaions you want to add to it
use
transform.Roate(-Input.GetAxis ("$$anonymous$$ouse Y") * mousespeed,0,0,space.self);
transform.Roate(0,0,Input.GetAxis ("$$anonymous$$ouse X") * mousespeed);
if you set the Rotation that is its absolute value in world coords so you are ignoring all rotations from the parent
Or
and this might be easier actualy
change your last line of code to
transform.localRotation = Quaternion.Euler (xRotation,0,0);
but i have not tried this
nice it works now :D
Thanks very much :DD
i use "transform.localRotation" and it works
Your answer
Follow this Question
Related Questions
Runescape Camera Rotation? 0 Answers
camera rotation interferes with controller rotation 0 Answers
How to freeze rotation of the camera 1 Answer
Spline controller problems? 0 Answers
Rotating camera problem C# Android 2 Answers