- Home /
Offsetting local positions
I have been trying to figure out how to use a vector3 as a offset for local transforms in scripting.
Ex: An orbit camera looking at a the player. I want to use a vector3 to position the lookat point slightly to the right of character. Also, when I rotate the camera, the offset should rotate with the camera so the offset stays on the right. Instead of that happening, the offset moves the lookat point on the world x-axis instead of the local axis.
How do I get it to offset on the local axis?
Answer by GameVortex · Nov 18, 2013 at 11:22 AM
So you want the position to be on the right of the player relative to the camera?
You are close, you just have to move it with the cameras axis instead of world as you said.
It can be done like this:
Vector3 playerPosition;
float xOffset;
Camera camera;
Vector3 lookAtPoint = playerPosition + (camera.transform.right * xOffset);
Hey thanks for the help. This is what I have been looking for. :)
Answer by Shudrum · Nov 18, 2013 at 11:19 AM
Why not use a empty gameobject ?
You create a gameobject "target" set the character as parent of this target (on the editor), your camera look at this target, so when you move / rotate your character, the target follow the movement and your camera still look at the right point.
(And maybe set the camera the children of this target).
As much as i have tried to use what I thought would be simpler by having a Vector3 offset for my camera that the Player script owns I've had little joy with that approach... with an empty game object CamTarget you position it, and reference it and all the hard work is done.
Your answer
![](https://koobas.hobune.stream/wayback/20220613122128im_/https://answers.unity.com/themes/thub/images/avi.jpg)