Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Help  Grab Rope - VR
#41
Hey everyone,

Just came to this forum for a completely unrelated reason and came across this thread. Coincidentally just solved this problem this week to build a grappling hook in the vanilla SteamVR 2.0 unity plugin. Proof:



The trick was getting steamVR to interact with the obi particles. Here's my ROUGH, unpolished code:



using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.Events;
using Obi;
using Valve.VR;

[RequireComponent(typeof(ObiSolver))]
public class RopeClimb : MonoBehaviour
{
    public ObiSolver solver;
    protected Valve.VR.InteractionSystem.VelocityEstimator velocityEstimator;

    public GameObject Player;

    public float releaseVelocityTimeOffset = -0.011f;

    private CharacterController m_CharacterController;
    private bool detectingCollisions = true;

    private Valve.VR.InteractionSystem.Hand draggingHand = null;
    void Start()
    {
        m_CharacterController = Player.GetComponent<CharacterController>();
    }

    void Update()
    {
        // subscribe to collision
        if (detectingCollisions == true) {
            solver.OnCollision += Solver_OnCollision;
            detectingCollisions = false;
        }

        // only set upon successful collision + grip
        if (draggingHand != null) {
            DragMove(draggingHand);
        }
    }

    void Solver_OnCollision(object senderObi.ObiSolver.ObiCollisionEventArgs e)
    {
        var world = ObiColliderWorld.GetInstance();
        foreach (Oni.Contact contact in e.contacts)
        {
            // this one is an actual collision:
            if (contact.distance < 0.01)
            {
                ObiColliderBase collider = world.colliderHandles[contact.other].owner;
         
                if (collider != null && collider.gameObject.tag == "VRHand")
                {
                    Valve.VR.InteractionSystem.Hand hand = collider.gameObject.GetComponent<Valve.VR.InteractionSystem.Hand>();
                    // set that we are currently dragging
                    draggingHand = hand;
                }
            }
        }
    }

    void DragMove(Valve.VR.InteractionSystem.Hand hand) {
        Vector3 velocity;
        Vector3 massagedVelocity;
        Vector3 angularVelocity;
        Vector3 currentPositon = hand.transform.position;
        Valve.VR.InteractionSystem.GrabTypes startingGrabType = hand.GetGrabStarting();
        if (velocityEstimator != null) {
            velocityEstimator.BeginEstimatingVelocity();
        }
        velocity = hand.GetTrackedObjectVelocity(releaseVelocityTimeOffset);
        angularVelocity = hand.GetTrackedObjectAngularVelocity(releaseVelocityTimeOffset);
        massagedVelocity = -velocity / 25//arbitrary
        Valve.VR.InteractionSystem.GrabTypes bestGrabType = hand.GetBestGrabbingType();

        if ( bestGrabType != Valve.VR.InteractionSystem.GrabTypes.None && hand.currentAttachedObject == null) {
            hand.Hide();
            m_CharacterController.Move(massagedVelocity);

        }

        // upon release grip, stop dragmove state
        // TODO - unset when out of range (can't drag forever)
        if ( bestGrabType == Valve.VR.InteractionSystem.GrabTypes.None ) {
            hand.Show();
            draggingHand = null;
        };
    }
}





A couple of notes:

-I tagged the VR hands with the tag "VRHand".

-I added a simple box collider with "trigger" set to true and Obi Collider to Valve's VR hands on the Player object.

-You have to pass in the player object and Obi Solver to the script. There's probably a better way of doing this. Like I said, this is an unpolished script!

-If you want to have this "grab" the rope particle instead of climbing it in a dragmove style, you could apply the velocity from the hands ("velocity" in the script) to the velocity of the currently grabbed rope particle (could be derived from "collider" in the script here, could create new top-level private variable "activeParticle" and set it when grabbed).
Reply


Messages In This Thread
Grab Rope - VR - by zig420 - 13-08-2020, 05:30 PM
RE: Grab Rope - VR - by Aento - 23-09-2020, 02:53 PM
RE: Grab Rope - VR - by josemendez - 23-09-2020, 02:54 PM
RE: Grab Rope - VR - by josemendez - 23-09-2020, 03:17 PM
RE: Grab Rope - VR - by zig420 - 02-12-2020, 04:08 AM
RE: Grab Rope - VR - by josemendez - 02-12-2020, 08:37 AM
RE: Grab Rope - VR - by zig420 - 02-12-2020, 09:55 PM
RE: Grab Rope - VR - by josemendez - 03-12-2020, 12:57 AM
RE: Grab Rope - VR - by zig420 - 14-12-2020, 04:24 PM
RE: Grab Rope - VR - by josemendez - 15-12-2020, 09:20 AM
RE: Grab Rope - VR - by Xanduffy - 22-01-2021, 08:32 PM
RE: Grab Rope - VR - by Aento - 24-09-2020, 12:47 PM
RE: Grab Rope - VR - by Xanduffy - 27-01-2021, 05:05 PM
RE: Grab Rope - VR - by josemendez - 27-01-2021, 09:03 PM
RE: Grab Rope - VR - by Xanduffy - 31-01-2021, 08:39 PM
RE: Grab Rope - VR - by josemendez - 01-02-2021, 07:38 AM
RE: Grab Rope - VR - by Xanduffy - 04-02-2021, 12:03 PM
RE: Grab Rope - VR - by josemendez - 04-02-2021, 12:09 PM
RE: Grab Rope - VR - by Xanduffy - 04-02-2021, 01:14 PM
RE: Grab Rope - VR - by josemendez - 04-02-2021, 01:52 PM
RE: Grab Rope - VR - by Xanduffy - 04-02-2021, 08:17 PM
RE: Grab Rope - VR - by josemendez - 05-02-2021, 09:43 AM
RE: Grab Rope - VR - by josemendez - 05-02-2021, 09:51 AM
RE: Grab Rope - VR - by Xanduffy - 05-02-2021, 07:25 PM
RE: Grab Rope - VR - by josemendez - 05-02-2021, 08:25 PM
RE: Grab Rope - VR - by Xanduffy - 05-02-2021, 10:10 PM
RE: Grab Rope - VR - by josemendez - 08-02-2021, 11:00 AM
RE: Grab Rope - VR - by Xanduffy - 09-02-2021, 05:17 PM
RE: Grab Rope - VR - by josemendez - 09-02-2021, 09:33 PM
RE: Grab Rope - VR - by Xanduffy - 09-02-2021, 09:04 PM
RE: Grab Rope - VR - by josemendez - 09-02-2021, 09:33 PM
RE: Grab Rope - VR - by Xanduffy - 09-02-2021, 11:10 PM
RE: Grab Rope - VR - by josemendez - 10-02-2021, 12:41 PM
RE: Grab Rope - VR - by Xanduffy - 10-02-2021, 06:29 PM
RE: Grab Rope - VR - by josemendez - 11-02-2021, 09:33 AM
RE: Grab Rope - VR - by tpaslou - 16-02-2021, 01:57 PM
RE: Grab Rope - VR - by josemendez - 16-02-2021, 02:02 PM
RE: Grab Rope - VR - by tpaslou - 16-02-2021, 02:36 PM
RE: Grab Rope - VR - by Xanduffy - 17-02-2021, 05:03 PM
RE: Grab Rope - VR - by polymod - 18-02-2021, 03:40 AM
RE: Grab Rope - VR - by mo1ok - 18-02-2021, 04:16 AM
RE: Grab Rope - VR - by Xanduffy - 19-02-2021, 09:35 PM
RE: Grab Rope - VR - by josemendez - 22-02-2021, 12:28 PM
RE: Grab Rope - VR - by tpaslou - 22-02-2021, 12:11 PM
RE: Grab Rope - VR - by josemendez - 22-02-2021, 12:21 PM
RE: Grab Rope - VR - by tpaslou - 23-02-2021, 12:42 PM
RE: Grab Rope - VR - by josemendez - 23-02-2021, 12:45 PM
RE: Grab Rope - VR - by tpaslou - 24-02-2021, 10:35 AM
RE: Grab Rope - VR - by josemendez - 24-02-2021, 10:39 AM
RE: Grab Rope - VR - by tpaslou - 24-02-2021, 10:56 AM
RE: Grab Rope - VR - by josemendez - 24-02-2021, 11:06 AM
RE: Grab Rope - VR - by josemendez - 24-02-2021, 11:17 AM
RE: Grab Rope - VR - by tpaslou - 24-02-2021, 11:58 AM
RE: Grab Rope - VR - by josemendez - 24-02-2021, 12:14 PM
RE: Grab Rope - VR - by tpaslou - 24-02-2021, 02:00 PM
RE: Grab Rope - VR - by Xanduffy - 04-03-2021, 12:50 AM
RE: Grab Rope - VR - by Xanduffy - 04-03-2021, 02:05 PM