Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Help  Grab Rope - VR
#15
(27-01-2021, 09:03 PM)josemendez Wrote: You should not use this script to grab the rope if yoy expect to be able to do it with both hands at once. The reason for this is that it basically parents particles to the colliders in touch, which will enable to to overstretch the rope.

Unless overstretching is fine for you, a better approach would be to use pin constraints for this and use two-way coupling with the hands (similar to what half-life alyx does). That way the VR hands would not be able to pull further once the rope is completely taut.

Regarding the issue with not being able to grab certain particles, there’s no reason for it that I can think of. Only contact distance between colliders is taken into account. This is a long shot but: maybe  there’s no contacts being generated for some particles, due to them having the same phase as the collider?

I took your advice and have spent the last few days attempting to implement a grab function that generates pin constraints at the location of the first particle in a collision, called by a controller input and I must admit I'm a little lost. I've been referencing this script, alongside the aforementioned 2017 script by nizmo and the sample pin constraints script located in the documentation, but I don't seem to be getting anywhere and would really appreciate some guidance. I'll provide my current script which is intended to be attached to the player's hands, though it does nothing currently. Attempting to grab the rope causes a small reaction in the rope mesh but there is no attachment or influence on the particles it seems. I hope you can help and tell me where I've gone wrong.

As for the phase question, the hand colliders are set to phase 6 to avoid that, so I'm not sure that was the cause.
Code:
using UnityEngine;
using System.Collections;
using System.Collections.Generic;
using Obi;

[RequireComponent(typeof(ObiCollider))]
public class RopeGrabber : MonoBehaviour
{
    public bool canGrab = true;
    ObiSolver solver;
    ObiCollider obiCollider;
    public ObiRope rope;
    ObiSolver.ObiCollisionEventArgs collisionEvent;
    ObiPinConstraintsBatch newBatch;
    ObiConstraints<IObiConstraintsBatch> pinConstraints;

    void Awake()
    {
        solver = FindObjectOfType<ObiSolver>();
        obiCollider = GetComponent<ObiCollider>();

        // get a hold of the constraint type we want, in this case, pin constraints:
        pinConstraints = rope.GetConstraintsByType(Oni.ConstraintType.Pin) as ObiConstraints<IObiConstraintsBatch>;
    }

    private void OnEnable()
    {
        if (solver != null)
            solver.OnCollision += Solver_OnCollision;
    }

    private void OnDisable()
    {
        if (solver != null)
            solver.OnCollision -= Solver_OnCollision;
    }

    private void Solver_OnCollision(object sender, Obi.ObiSolver.ObiCollisionEventArgs e)
    {
        collisionEvent = e;
    }

    public void Grab()
    {
        var world = ObiColliderWorld.GetInstance();

        if (solver != null && collisionEvent != null)
        {
            foreach (Oni.Contact contact in collisionEvent.contacts)
            {
                if (contact.distance < 0.01f && canGrab)
                {
                    var contactCollider = world.colliderHandles[contact.other].owner;

                    if (contactCollider == obiCollider)
                    {
                        var batch = new ObiPinConstraintsBatch();
                        batch.AddConstraint(rope.solverIndices[contact.particle], obiCollider, Vector3.zero, Quaternion.identity, 0, 0, float.PositiveInfinity);
                        newBatch = batch;
                        pinConstraints.AddBatch(newBatch);

                        canGrab = false;

                        // this will cause the solver to rebuild pin constraints at the beginning of the next frame:
                        rope.SetConstraintsDirty(Oni.ConstraintType.Pin);

                    }

                }
            }
        }
    }

    public void Release()
    {
        pinConstraints.RemoveBatch(newBatch);
        rope.SetConstraintsDirty(Oni.ConstraintType.Pin);
        canGrab = true;
    }

}
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