VR Ladder

Hello all,

I hope I’m posting this in the right area.

in short:
I want to have the player climb up a ladder using the rungs of the ladder. Can any one give me a hand or point me in the right direction?

in long:
the event chain I invasion is as follows:
1)The player will move his controller’s spherical-collider into the collider of the rung.
2) the player clicks and hold a button(tag check).
3)the player is attached to the rung, the player’s hand/controller will stay fixed to the rung until release(no longer free to float around).
4)as he moves his controller up/down his body rig will move in the opposite direct(for ascent/decent).
5) player releases the button and is detached from the rung.

I am pretty new to Unity and VR, but I’ve been looking at tutorials and it doesn’t seem like it should be too difficult. A force based movement seems to be the best way to do it. so that environmental affects can pull/blow you off.
ive been trying to addapt one of the Vive minuet tutorials (

) to do this. just adding a grabbed bool and then trying to figure out how to get the logic right.

in the following code it seems to be line#47 where i try to move the player based on the controller movement that seems to be wrong.
for some reason when i move click the button, the controller jumps to the world origin. and also the player camera wont move with the controller movement.

ps.
ive edited this code to cut of some artifacts from previous attempts.

public class ClimbLadder01: MonoBehaviour
{

    private Valve.VR.EVRButtonId triggerButton =
    Valve.VR.EVRButtonId.k_EButton_SteamVR_Trigger;

    public SteamVR_Controller.Device controller { get { return
    SteamVR_Controller.Input((int)trackedObj.index); } }
    public SteamVR_TrackedObject trackedObj;
    public Transform eyeTransform; //the [CameraRig] from the valve SDK

    public GameObject obj;
    public bool grabbed;

    public Rigidbody rig;


    void Start()
    {

        trackedObj = GetComponent<SteamVR_TrackedObject>();
        fJoint = GetComponent<FixedJoint>();
    }


    void Update()
    {

        if (controller.GetPressDown(triggerButton))
        {
          
            Debug.Log("trigger down");
            PickUpObj();  
        }
        if (controller.GetPressUp(triggerButton))
        {
                       
            Debug.Log("trigger up");
            DropObj();
        }

    private void FixedUpdate()
    {

        if (grabbed)//well move the camera based on the controllered movment.
        {
           eyeTransform.position = eyeTransform.position - this.gameObject.transform.position;
   
        }

    void OnTriggerStay(Collider other)//built in event from unity
    {
        if (other.CompareTag("PickUpable"))
        {
            obj = other.gameObject;
            //Debug.Log("enter");
           
        }
    }
void PickUpObj()
    {
       
        if (obj != null)
        {
           
            fJoint.connectedBody = obj.GetComponent<Rigidbody>();
            throwing = false;
            rig = null;
           
            grabbed = true;
        }
        else
        {
            fJoint.connectedBody = null;
            throwing = false;
        }
    }

void DropObj()
    {
       
        if (obj != null)
        {
            rig = fJoint.connectedBody;
            fJoint.connectedBody = null;                  
            grabbed = false;
           
        }

    }

}

I’ve done something like this already.

You don’t want to move the Eye transform. You want to move the SteamVR CameraRig object, the top-most parent of your VR player setup. The Eye is controlled by the rig, so attempting to move it will just be countered by the rig.

To get that to work, I attached a rigidbody to the rig itself, so it could be moved with physics, while the colliders were attached to the individual child components (head and hands).
You don’t want to alter the transform’s position directly like you’re doing if you want the player to be effected by physics. You will want to find the hand’s world velocity (current world position - last world position), and apply that to your rig’s velocity.

Hope that helps :slight_smile:

Thanks, ill give it a try!