I have two GameObjects in my scene that I am trying to frame in a camera. I have the GameObjects stored as pc and npc. I am doing the following to get the midpoint between them:
which works fine, the object holding my camera ends up between them. However, from this point on I am brickwalling (due in no small part to my limited understanding of vectors). What I want to do is move the camera object perpendicular to the line between the players, so that it’s off to the side of them a bit. However, when I try:
dcam.transform.localPosition += new Vector3(5,0,0);
with dcam being my actual camera, it’s still moving the camera along the world axes and not along the local axes.
localPosition moves the camera along its location relative to its parent. It’ll always move along world space when translated whether it’s in position or localPosition.
What YOU want is transform.right, transform.forward, or transform.up. Those vectors give the camera’s position relative to itself.
For instance, if you wanted to move it three spaces down relative to itself, you’d do this: transform.Translate(-transform.up * 3);