- Home /
Offset against Rotated Object,Applying Offset to a Rotated Transform
I'm currently working on a project where the offset and orientation of the player's camera relative to a viewport will be mimicked by a camera relative to a target point (viewspace) elsewhere. I expect this target point to rotate about its y-axis and I want the associated camera to pivot with it.
Based on the code below, I would expect that the camera would move in world units (so if the offset is Vec3(1,0,0) but the target, at (0,0,0) is rotated by -90 degrees, then the camera move to (1,0,0) rather than (0,-1,0).
What would I need to change to get the second camera to move relative to the viewspace (in short, how do I get the camera to pivot around viewspace as it rotates)?
void Update()
{
Vector3 playerOffsetFromWindscreen = playerCamera.position - windscreen.position;
transform.position = viewSpace.position + playerOffsetFromWindscreen;
}
Answer by AlbieMorrison · Sep 29, 2020 at 02:55 AM
Make the second camera a child of the viewspace and set its relative offset to the viewspace using the xyz position, then use transform.rotate to pivot it around the starting point.