- Home /
XR Controller (XR Ray Interactor) rotation and position offset?
I cant seem to find a way to offset the native rotation of my XR controller. Its not a big deal for the direct Interactor since i can rotate the controller Model and move the Transform. However for the XR Ray Interactor, no matter how my Hand model is rotated, the ray always shoots out from a (atleast for me with the Index controller) very uncomfortable angle.
Ive added an illustration to explain what i mean:
The Ray interactor always hast to be attached to the same GameObject as the XR Controller so i cant just add the Interactor as a Child to the GameObject.
Answer by ChrisWarner103 · Mar 12, 2021 at 12:58 AM
I'm not too sure if you managed to solve this at all or anything. But I managed to find out a way to change the position of where the Raycast starts. I went through the XRRayInteractor script and found a transform variable that was used called "startTransform" which is then referenced to the Original Attach Transform. Which is the instanced empty GameObject called "[Controller] Original Attach" by moving this object it changes where the Raycast originates from. (Extra note, the OriginalAttachTransform also copies the AttachTransform reference after interacting with an object. So by setting that, it'll set the Original Attach Transform by default)
Which is the object that I have selected in the screenshot below:
I hope this helps you out and anyone else that finds this thread!
Answer by andykibz · Nov 07, 2021 at 05:15 PM
If anyone still needs a solution for this, create an empty with your desire transform(position and rotation, then use it in the Attach Transform field of the XR Ray Interactor. .
Answer by gagarin-interactive · Jan 20, 2021 at 02:18 AM
Did you figure this out? I am also trying to offset the ray but cant figure out how - without using a hackish workaround. At runtime an gameobject called "original attach" is added under the controller. This is the object used to offset the ray.
Not yet unfortunately. But your hint with the original Attach sounds promising! Thank you for that! Ill have a look into it this Evening. $$anonymous$$aybe there is away to offset it on Awake or Start to match the transform of a reference Object for excample :)
You can create an empty GO as a child of the controller as a custom AttachTransform with desired transform and assign it in your XRRayInteractor's Attach Transform slot. This overrides the automatic creation of an AttachTransform and sets the orientation and origin of the ray as you wish.
Answer by ArtIsEverything · Apr 14, 2021 at 10:17 PM
okay so there is a very dumb way of fixing this, and I fully would appreciate if someone found a better way. But the way I did it was to create a script on an empty object that on Start() does a GameObject.Find on the Attach and Original Attach objects, uses GetComponent-Transform()-.rotation to get the rotation and sets it manually. It ain't pretty, but it works! Also you should remember for this that the Euler function has a weird order of z,x,y so make sure if you take a Vector3 input to switch the numbers around before applying them as the rotation. It's stupid but it works!
Answer by Muskie · Nov 12, 2021 at 07:08 AM
I have discovered a solution to this issue:
Remove the XR Ray interactor, Line Renderer, and XR Interactor Line Visual components from the controller object.
Create an empty gameobject as a child of the controller, and name it appropriately (RayInteractorOrigin or whatever).
Add the XR Ray Interactor, Line Renderer, and XR Interactor Line Visual components to the child. DO NOT add an XR Controller component. This will be handled by the XR controller object in the parent object.
The interactor Raycasts will now originate from the new object. No need to use Attach Transforms.
Quick note: The Raycast will point towards vector3.forward (the X (Blue) Axis) of the RayInteractorOrigin Object. You'll need to rotate the object accordingly so it points the way you want.
Your answer
Follow this Question
Related Questions
How to write a script to disable position and rotation tracking for VR 0 Answers
Use SteamVR and Vive controller or tracker ONLY for position tracking, no headset 1 Answer
How do I determine the rotation of the XR unity controller if it is held upright or held facing down 2 Answers
HTC Vive Controller Twist - Extracting Angular Velocity On The Correct Axis 0 Answers