#```csharp
1 messages · Page 1 of 1 (latest)
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
I don't understand what you want
I'm confused
what are you trying to do exactly?
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
currently (0, 1.5, 0)
does that change?
@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
what are you trying to achieve on the grand scale?
center the player at the rootPosition
why
that's not how axes work. You are defining some weird axis that runs from (0,0,0) to (rootPosition + Vector3.up). You're not offseting it
like what is the purpose of this? Im trying to wrap my head around what you're doing
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
how do i rotate around the axis facing up at the rootPosition?
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?
it's a surgery room in VR
rotate doesn't move an object through space. It just rotates it in place. If you want to rotate around an axis that does not run through the pivot of your object, you need to both rotate and translate
do you know the right combination of rotating and translating to do that?
you are overthinking it. its just a function that makes the player reset to the center of the room (the rootPosition) facing forwards
you can see the floor offset is the parent of the player's camera and controllers and it has the calibration script
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.
idk you tell me
well the camera's position is driven by the tracked pose driver so you can't really mess with it
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
looks good. will this not work?
trying it out
probably your rotation should be Quaternion.AngleAxis(angle, Vector3.up)
I got to run... Good luck!
thanks!
bruh it literally "just works"
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);
}