Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Help  grabbing rope and holding on to it
#1
Hi,
I am working on a VR game, I want my player hands to grab a rope with one hand and swing on it.
But I ran into some issues, essentially the player is able to grab the rope initially, but I not able to get my player to hold on to the rope when he moves (he is able to move very far away from the rope after grabbing it, but the shape of the rope looks good though).
I want the rope constrain his move once it's grabbed, I don't want the rope to strech much.
Note that I don't have a ton of experience with Unity (apologies in advance for any basic question). But I did some research, including this useful thread http://obi.virtualmethodstudio.com/forum...-2907.html.

So far I got the grabbing part partially working by:
1- Modifying the ObiContactGrabber slightly to create an attachment to the right hand game object when the player is able to grab the rope (instead of setting the grabbed particle inverse mass to 0).
I set the attachment type to dynamic. Otherwise the rope seemed to strech to the infinite when I tested (my understanding is that I need 2 way coupling).
2- adding ObiCollider and ObiRigidBody script to the hand game object.
Initially ObiRigidBody and RigidBody have kinematic (and kinematic for particles) set to true (otherwise I wasn't able to grab the rope, not sure why yet, I need to research it still)
When the particle is grabbed my script sets kinematic to false on the RigidBody and ObiRigidBody. That way the rope does not strech much when I move the player (and its hand).
The code run when grabbing the particle is successful looks like:
       
Code:
var solver = particle.solver;
        var actor = solver.particleToActor[particle.index].actor;
        var group = ScriptableObject.CreateInstance<ObiParticleGroup>();
        group.particleIndices.Add(particle.index); // index of the particle in the actor
        handAttachment = rope.AddComponent<ObiParticleAttachment>();
//player transform is the right hand transform here
        handAttachment.target = playerTransform;
        handAttachment.particleGroup = group;
        handAttachment.attachmentType = ObiParticleAttachment.AttachmentType.Dynamic;
//this was needed so the rope doesn't stretch indefinitely when player moves far away from it
// setting kinematic to false for the hand rigidBody
        ObiRigidbody orb = playerTransform.GetComponent<ObiRigidbody>();
        orb.kinematicForParticles = false;
        Rigidbody rb = playerTransform.GetComponent<Rigidbody>();
        rb.isKinematic = false;

Note that I am using continuous locomotion in VR to move the player (all based on UnityXR, XRInteraction toolkit).

So my current issue is that when the player grabs the rope then moves far from it, the shape of the rope looks good (doesn't stretch) but the player can still move very far.
But I want the player's hand to be stuck to the rope particle.
The concept seems to work with dynamic attachment in general (I was able to get a simple pendulum working).
So I suspect this is an issue related to logical conflicts between VR player locomotion and the Obi solver logics. I need the rope to 'pull back' the hand when it goes too far.
Any suggestion on how I can get this implemented?
I could probably figure out some scripting logic to force repositioning the hand (and player) close to the particle in one of the unity update() methods but not sure if I will succeed, and I was hoping for a simpler solution.

Eventually I want my player to be able to swing on the rope when he jumps (so hand and player stuck on the rope and no infinite rope stretching is definitely important). Not surehow/ if this will impact the solution.
Thanks in advance for the help.
Reply


Messages In This Thread
grabbing rope and holding on to it - by lbouis - 29-06-2023, 01:42 AM