Hi there, I'm trying to make a very basic cam follow script. The thing is that the camera has to follow x-rotation of 1 transform and the y- and z-rotation of another. It currently does this, however, it does not also look at any of the targets (as it rotates in the same manner). My question is: How can I have the camera look at (and follow) the target(s) while also following the z-rotation of the yzTransform? Here is the code so far... BTW the two transforms are parent and child (yzTarget -> xTarget) at the same position so it does not matter which transform the camera looks at as long as the rotation follows the specifications above... The code so far: Code (CSharp): void Update () { //Vector3 targetPos = new Vector3(xTarget.position.x, yzTarget.position.y, yzTarget.position.z); Quaternion q = Quaternion.Euler(xTarget.eulerAngles.x, yzTarget.eulerAngles.y, yzTarget.eulerAngles.z); transform.rotation = Quaternion.Slerp(transform.rotation, q, rotationSpeed * Time.deltaTime); //transform.position += transform.forward * moveSpeed * Time.deltaTime; }
I had a look at the video you suggested. It does however not really address the issue I am currently having. The problem with using transform.LookAt(target.position) is that it does not follow the local z-rotation of the transform controlling the rolling (z-rotation). I am therefore back to rotating the appropriate axes with the right angles but not looking at the transform(s) being controlled. Any suggestions as to how to achieve this? This is what I have now: Code (CSharp): void LateUpdate () { transform.position = targetYZ.position - offset; // transform.LookAt(targetYZ.position); transform.RotateAround(target.position, targetYZ.up, targetYZ.eulerAngles.y); transform.RotateAround(target.position, targetX.right, targetX.eulerAngles.x); transform.RotateAround(target.position, targetYZ.forward, targetYZ.eulerAngles.z); }
I think you have to change global xyz to local xyz. I had that problem a while back, can't remember what I did. I will go back and see if I can find the script.
I've never tried to adjust all 3 axis for a camera setup, so I can't be 100% sure this will work.. However, for myself (and others who ask questions about 1/2 axis) - it's really helpful if you have a 3-part camera rig. For 2 axis, for example, the rig is an empty game object. It has an empty game object child, and that child has the Camera. When the x rotation is changed, just the top object adjusts to match, and for the y-rotation, it's the first child. This, plus some code to update it's position (and set values for offset on the game object in the scene), the camera and its rotation work out very nicely. I dunno if that's helpful for you. (maybe with 3 axis, you add another child that does the 'z'?) lol. Sorry I can't be more specific, because I've never tried it