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


Messages In This Thread
Swinging rope not behaving right - by aphixe - 10-12-2018, 03:40 AM
RE: Swinging rope not behaving right - by aphixe - 10-12-2018, 09:33 AM