Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Swinging rope not behaving right
#1
Problem I am having with how the rope is behaving, not sure how to fix it or what not. I did have some troblem with the code I used a ObiPinConstraintBatch, which for whatever reason was missing on the http://obi.virtualmethodstudio.com/tutor...aints.html page, unless i am wrong.  code is at end if it helps.
I want to be able to swing with the rope.


[Image: ftJz131.jpg]

Code:
using UnityEngine;
using System.Collections.Generic;
using Obi;

[RequireComponent(typeof(ObiSolver))]
public class grabrope : MonoBehaviour
{
   [SerializeField]
   private ObiRope rope;
   public ObiCollider character;  // add player in inspector with obi collider
   public float ropeOffset = .25f;
   private int particleLocation = 7; //sets where player is attached on rope.
   ObiSolver solver;

   Obi.ObiSolver.ObiCollisionEventArgs collisionEvent;

   void Awake()
   {
       solver = GetComponent<Obi.ObiSolver>();
       rope = GetComponent<ObiRope>();
   }

   void OnEnable()
   {
       solver.OnCollision += Solver_OnCollision;
   }

   void OnDisable()
   {
       solver.OnCollision -= Solver_OnCollision;
   }

   void Solver_OnCollision(object sender, Obi.ObiSolver.ObiCollisionEventArgs e)
   {
       foreach (Oni.Contact contact in e.contacts)
       {
           if (contact.distance < 0.01)
           {
               Component collider;
               if (ObiCollider.idToCollider.TryGetValue(contact.other, out collider))
               {
                   if (Input.GetKeyDown(KeyCode.E))
                   {
                       rope.PinConstraints.RemoveFromSolver(null);
                       ObiPinConstraintBatch batch = (ObiPinConstraintBatch)rope.PinConstraints.GetFirstBatch();
                       batch.AddConstraint(particleLocation, character, Vector3.up * ropeOffset, 1);
                       rope.PinConstraints.AddToSolver(null);
                   }
                 
               }
           }
       }
   }

}
Reply
#2
(10-12-2018, 03:40 AM)aphixe Wrote: Problem I am having with how the rope is behaving, not sure how to fix it or what not. I did have some troblem with the code I used a ObiPinConstraintBatch, which for whatever reason was missing on the http://obi.virtualmethodstudio.com/tutor...aints.html page, unless i am wrong.  code is at end if it helps.
I want to be able to swing with the rope.


[Image: ftJz131.jpg]

Code:
using UnityEngine;
using System.Collections.Generic;
using Obi;

[RequireComponent(typeof(ObiSolver))]
public class grabrope : MonoBehaviour
{
   [SerializeField]
   private ObiRope rope;
   public ObiCollider character;  // add player in inspector with obi collider
   public float ropeOffset = .25f;
   private int particleLocation = 7; //sets where player is attached on rope.
   ObiSolver solver;

   Obi.ObiSolver.ObiCollisionEventArgs collisionEvent;

   void Awake()
   {
       solver = GetComponent<Obi.ObiSolver>();
       rope = GetComponent<ObiRope>();
   }

   void OnEnable()
   {
       solver.OnCollision += Solver_OnCollision;
   }

   void OnDisable()
   {
       solver.OnCollision -= Solver_OnCollision;
   }

   void Solver_OnCollision(object sender, Obi.ObiSolver.ObiCollisionEventArgs e)
   {
       foreach (Oni.Contact contact in e.contacts)
       {
           if (contact.distance < 0.01)
           {
               Component collider;
               if (ObiCollider.idToCollider.TryGetValue(contact.other, out collider))
               {
                   if (Input.GetKeyDown(KeyCode.E))
                   {
                       rope.PinConstraints.RemoveFromSolver(null);
                       ObiPinConstraintBatch batch = (ObiPinConstraintBatch)rope.PinConstraints.GetFirstBatch();
                       batch.AddConstraint(particleLocation, character, Vector3.up * ropeOffset, 1);
                       rope.PinConstraints.AddToSolver(null);
                   }
                 
               }
           }
       }
   }

}

The problem is probably not in the rope but in your character:
- Is your character a non-kinematic rigidbody? It needs to in order to be affected by rope physics.
- What is the mass ratio between the character and the rope particles?
Reply
#3
(10-12-2018, 08:06 AM)josemendez Wrote: The problem is probably not in the rope but in your character:
- Is your character a non-kinematic rigidbody? It needs to in order to be affected by rope physics.
- What is the mass ratio between the character and the rope particles?

I mean mass on regular rigidbody is 50, i tried adjusting it to 10, character get lifted up, but if i move forward it swings like forward but stays there. I looked at the RopeGrapplingHook to see what you set for mass and as well as kinematic setting. and my character doesn't have a kinematic set on. the particles mass hasn't been changed in edit particle. only particle I have set static is top i fixed it in mid air. Perhaps if I have some resources I can read about the physics. I did read the pages on settings, but other sources may help clear up why its not working.
Reply
#4
(10-12-2018, 09:33 AM)aphixe Wrote: I mean mass on regular rigidbody is 50, i tried adjusting it to 10, character get lifted up, but if i move forward it swings like forward but stays there. I looked at the RopeGrapplingHook to see what you set for mass and as well as kinematic setting. and my character doesn't have a kinematic set on. the particles mass hasn't been changed in edit particle. only particle I have set static is top i fixed it in mid air. Perhaps if I have some resources I can read about the physics. I did read the pages on settings, but other sources may help clear up why its not working.

If your character is not kinematic (does not have the kinematic checkbox enabled) the leave it as-is.

Try to get the mass ratio under 10 (so if particles are 0.01 kg, your character can be 1 kg max). There's a thread discussing mass ratios here:
http://obi.virtualmethodstudio.com/forum...mass+ratio

The effect of having a heavy character attached to a light rope is that the character will push the rope more than the rope pushes the character, which is the opposite of what you want. Just like in real life: if a heavy object collides with a light object, the light object will move a lot, but the heavier one will not.

You can get stiffer rope by increasing the amount of distance constraint iterations or reducing the tilmestep, but large mass ratios put more of a burden on the solver.
Reply