- Home /
How to make two cameras face the same direction?
I basically have two scipts controlling the same camera. One for Third Person, one for first person. When I switch between the two, I want them to face the same direction. My plan was to get the forward vector of one of the cameras and use transform.lookAt on the other, to face that direction, sadly that doesn't work as intended.
Drawing a ray with that method, starting at transform.position works perfectly fine. What do I do wrong?
You have to specify what you mean hyper-clearly.
Should they be looking at exactly the same object?
Should they be looking at exactly the same point, some certain distance away? (Say 5 meters - you'd have to exactly state the meters you mean.)
Should the line of sight of the two cameras be exactly parallel?
There are other possibilities but it's likely you mean one of those. The three I mention are totally and completely different in how you need to approach them. Fill us in !
Answer by whydoidoit · Sep 17, 2012 at 03:37 PM
Try:
camera2.transform.forward = camera1.transform.forward;
I don't quite understand your tip, and how this should work?
$$anonymous$$y idea was passing the direction from the 3. Person camera over to the 1. Person camera, converted to world space.
Vector3 globalForward = Transform.TransformDirection(transform.forward);
FP_Camera.Instance.setDirection(globalForward);
Afterwards I wanted to adjust the 1. person camera with it's script:
public void setDirection(Vector3 globalLookDirection)
{
Vector3 localLookDirection = transform.InverseTransformDirection(globalLookDirection);
transform.LookAt(localLookDirection);
}
What's my mistake behind this thought? Like I said, drawing a ray works as intended, but the camera doesn't get adjusted at all.
transform.forward is already in world space coordinates - there is no need to transform it. LookAt looks at something (a point in 3d space not a direction). Setting one transforms forward to another ones makes them look in the same direction - but to ensure that Up didn't change you could do:
camera2.transform.rotation = Quaternion.LookRotation(camera1.transform.forward, transform.up);
Okay, it doesn't work. I guess it's some problem with another part of my script, that I haven't thought of yet. After all, it's the same camera, just moved. When I just change it's position, the rotation shouldn't even change, therefor there should not be the need for a new rotation.
I'll just continue searching for the problematic part.
Thank you nonetheless!
@fattie is right in the comment above - I might have been too literal in my answer - it's possible this isn't the effect you are looking for!
Your answer
Follow this Question
Related Questions
1st person Camera rotates suddenly in another direction when unparenting from a platform 1 Answer
3drd person camera reset 0 Answers
Player rotation = Camera Rotation 0 Answers
TPS Rotation Camera (similar to WoW or any other mmo) 0 Answers
How to keep the player on the left side o the screen? 2 Answers