Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Help Offsetting Follow Transform script - VR Arm and Hand Rig - Oculus

Discussion in 'AR/VR (XR) Discussion' started by MajorThurman, Feb 11, 2020.

  1. MajorThurman

    MajorThurman

    Joined:
    Jan 3, 2020
    Posts:
    6
    Hi

    This is using Oculus Integration, also novice coder so please be gentle :/

    I have set up some VR arms and hands set up which I've got working perfectly (my hands are tracking the left and right hand ancheors and my Arm are set up ugin the animation IK etc) Currently I have my rig parented to the Center Eye Anchor which works okay but isnt ideal becasue my arms rotate when I rotate my HMD. What I actually want is for my rig to follow the HMD's position and follow the Tracking spaces rotation.

    I've written two scripts to do this...

    One for following the rotation of the Tracking Space - I drag the tracking space into the Follow Target Slot.

    using System.Collections;
    using System.Collections.Generic;
    using UnityEngine;

    public class FollowRotation : MonoBehaviour
    {
    public Transform FollowTarget;

    void Update()
    {
    if (FollowTarget)
    {
    transform.rotation = FollowTarget.rotation;
    }
    }
    }

    One to follow the position of the HMD - I drag the Centre Eye Acnhor into the Follow Target Slot.

    using System.Collections;
    using System.Collections.Generic;
    using UnityEngine;

    public class FollowTransform : MonoBehaviour
    {

    public Transform FollowTarget;

    void Update() {
    if(FollowTarget) {
    transform.position = FollowTarget.position;
    }
    }
    }

    So everything tracks perfect but I need to offset both the rotation and position.
    When I press play my rig needs rotating 90 degrees and the position needs adjusting on the Z axis but I dont know how to do this. Can anyone help me with my script to allow me to make adustements so I can position my rig so its perfect on play?

    Many thanks
     
  2. MajorThurman

    MajorThurman

    Joined:
    Jan 3, 2020
    Posts:
    6
    So ignore everyting I asked above, I'm a total douche bag :)

    I worked out how to do exactly what I wanted to do by creating an empty game object for the rotation and position, parenting them to the Center Eye Anchor and Tracking space and then using them in my scripts, which allowed me to set the offsets I needed, however I then realised that It wasnt what I actually wanted :) If you physicall rotate on the spot then your arms dont which is not what I wanted - i didnt realise until I actually set it up Doh!, so in actual fact the way I had it set up in the first place (parenting my rig to the Centre Eye Anchor) is actually what I need. I'm now investigating the Lerp function to give me some delay on the rotation so its not one to one.

    For those who looked at this post, sorry for wasting your time.