#```csharp

1 messages · Page 1 of 1 (latest)

plush olive
#

i can provide more details if necessary

#

i made this spreadsheet to simulate pressing the calibrate button constantly. it works, but doesn't take rotation into account, which is where my code breaks, too

quaint willow
#

I don't understand what you want

#

I'm confused

#

what are you trying to do exactly?

plush olive
#

im moving the floor offset so that the camera (child of floor offset) is moved to rootPosition

#

you can't just move the camera itself because its position and rotation is driven by the tracking

quaint willow
#

I see

#

so what is the root position

plush olive
#

currently (0, 1.5, 0)

quaint willow
#

does that change?

plush olive
#

@jolly widget ill simplify it to +=

the rotation axis is offset because i want to rotate around where the camera is being centered to, not (0, 0, 0) facing up

quaint willow
#

what are you trying to achieve on the grand scale?

plush olive
#

center the player at the rootPosition

quaint willow
#

why

jolly widget
quaint willow
#

like what is the purpose of this? Im trying to wrap my head around what you're doing

plush olive
#

because very often they spawn in in some weird position or their playspace's center is not where they want their anchor point

#

like if im sitting in my chair (not in the center of my room) and i spawn in way off to the side, i press a button and it puts me at the "starting point" of the scene

plush olive
quaint willow
#

so you have a floor, and the camera is above looking straight down and you're spawning in gameObjects and you want them in the center of the world?

#

like what is your game/program?

plush olive
#

it's a surgery room in VR

jolly widget
plush olive
#

do you know the right combination of rotating and translating to do that?

plush olive
#

you can see the floor offset is the parent of the player's camera and controllers and it has the calibration script

quaint willow
#

so you can just set the player's position to vector3.zero and rotation to Quaternion.identity or transform.forward = Vector3.forward?

#

im not overthinking it you're just being quite short scoped about what you want to happen.

plush olive
#

"the player's position"

#

you mean the camera position?

quaint willow
#

idk you tell me

plush olive
#

well the camera's position is driven by the tracked pose driver so you can't really mess with it

jolly widget
#
Quaternion rotation; // whatever rotation you're trying to do

Vector3 oldOffset = transform.position - rootPosition;
Vector3 newOffset = rotation * oldOffset;

transform.position = rootPosition + newOffset;
transform.rotation = transform.rotation * rotation;
#

I believe

quaint willow
#

looks good. will this not work?

plush olive
#

trying it out

jolly widget
#

probably your rotation should be Quaternion.AngleAxis(angle, Vector3.up)

#

I got to run... Good luck!

plush olive
#

thanks!

plush olive
#

100% perfectly

#
private void Calibrate(InputAction.CallbackContext callbackContext)
{
    // reset rotation so that translations are simple
    transform.rotation = Quaternion.identity;
    // offset localPosition by how far off the camera is from the correct position
    transform.localPosition += new Vector3(
                                    rootPosition.x - camera.position.x,
                                    rootPosition.y - camera.position.y,
                                    rootPosition.z - camera.position.z);
    // define a rotation that counteracts the camera's y rotation
    Quaternion rotation = Quaternion.AngleAxis(-camera.rotation.eulerAngles.y, Vector3.up);
    // use that rotation to rotate on an axis through the rootPosition
    transform.SetPositionAndRotation(rootPosition + (rotation * (transform.position - rootPosition)), rotation);
}
jolly widget
#

#math

#

Quaternions are really powerful when you use them right