10-12-2018, 08:06 AM
(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.
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?