Ropes have no collision - Schmaniel - 08-09-2021
Good day,
I am having troubles spawning ropes from the code.
I wrote my code very similar to GrapplingHook.cs (a sample scene).
I now have the problem that the so-spawned ropes have no collision. Here is the code from that.
Any ideas where the problem could be?
Code: public void SpawnWire(Vector3 end1, Vector3 localHit)
{
// Create the rope
GameObject emptyGameObjectForOneRope = new GameObject();
emptyGameObjectForOneRope.transform.parent = this.transform;
rope = emptyGameObjectForOneRope.AddComponent<ObiRope>();
ropeRenderer = emptyGameObjectForOneRope.AddComponent<ObiRopeExtrudedRenderer>();
//ropeRenderer.section = section;
ropeRenderer.uvScale = new Vector2(1, 5);
ropeRenderer.normalizeV = true;
ropeRenderer.uvAnchor = 0;
ropeRenderer.thicknessScale = 0.5f;
rope.GetComponent<MeshRenderer>().material = material;
// Setup a blueprint for the rope:
blueprint = ScriptableObject.CreateInstance<ObiRopeBlueprint>();
blueprint.resolution = 0.5f;
blueprint.thickness = 0.5f;
blueprint.pooledParticles = 100;
// Tweak rope parameters:
rope.selfCollisions = true;
rope.surfaceCollisions = true;
rope.collisionMaterial = obiCollisionMaterial;
// Add a cursor to be able to change rope length:
cursor = emptyGameObjectForOneRope.AddComponent<ObiRopeCursor>();
cursor.cursorMu = 0;
cursor.direction = true;
////////////////////////////////////////////////////
this.end1 = end1;
this.localHit = localHit;
StartCoroutine("CoRoutineXD");
// Procedurally generate the rope path (a simple straight line):
}
public IEnumerator CoRoutineXD()
{
yield return 0;
// Procedurally generate the rope path (not quite a simple straight line, I could change it back though):
blueprint.path.Clear();
blueprint.path.AddControlPoint(end1, Vector3.back, Vector3.forward, Vector3.up, 0.1f, 0.1f, 1, 1, Color.white, "Hook start");
blueprint.path.AddControlPoint(localHit, Vector3.forward, Vector3.back, Vector3.up, 0.1f, 0.1f, 1, 1, Color.white, "Hook end");
blueprint.path.FlushEvents();
// Generate the particle representation of the rope (wait until it has finished):
yield return blueprint.Generate();
// Set the blueprint (this adds particles/constraints to the solver and starts simulating them).
rope.ropeBlueprint = blueprint;
rope.GetComponent<MeshRenderer>().enabled = true;
//
// Pin both ends of the rope (this enables two-way interaction between character and rope):
var pinConstraints = rope.GetConstraintsByType(Oni.ConstraintType.Pin) as ObiConstraints<ObiPinConstraintsBatch>;
pinConstraints.Clear();
var batch = new ObiPinConstraintsBatch();
batch.AddConstraint(rope.solverIndices[0], gameObject.GetComponent<ObiCollider>(), localHit, Quaternion.identity, 0, 0, float.PositiveInfinity);
batch.AddConstraint(rope.solverIndices[blueprint.activeParticleCount - 1], gameObject.GetComponent<ObiCollider>(),
end1, Quaternion.identity, 0, 0, float.PositiveInfinity);
batch.activeConstraintCount = 2;
pinConstraints.AddBatch(batch);
rope.SetConstraintsDirty(Oni.ConstraintType.Pin);
cursor.ChangeLength(wireLength);
RE: Ropes have no collision - josemendez - 13-09-2021
If you're using 6.2, make sure you pass appropriate collision filters to the AddControlPoint() method when generating the rope path. Right now you're just passing 1.
Filters are a 32-bit integer where the 16 most significant bits define the collision mask, and the 16 less significant bits define the category (see collision filtering: http://obi.virtualmethodstudio.com/manual/6.2/collisions.html)
You can build the filter yourself using bitwise operations, and there's also helper functions if you don't want to mess with bits yourself. ObiUtils.MakeFilter will create the filter for you given a mask and a category. For instance:
Code: int filter = ObiUtils.MakeFilter(ObiUtils.CollideWithEverything,0);
This builds a filter for category 0 that collides with everything.
RE: Ropes have no collision - Schmaniel - 13-09-2021
(13-09-2021, 11:10 AM)josemendez Wrote: If you're using 6.2, make sure you pass appropriate collision filters to the AddControlPoint() method when generating the rope path. Right now you're just passing 1.
Filters are a 32-bit integer where the 16 most significant bits define the collision mask, and the 16 less significant bits define the category (see collision filtering: http://obi.virtualmethodstudio.com/manual/6.2/collisions.html)
You can build the filter yourself using bitwise operations, and there's also helper functions if you don't want to mess with bits yourself. ObiUtils.MakeFilter will create the filter for you given a mask and a category. For instance:
Code: int filter = ObiUtils.MakeFilter(ObiUtils.CollideWithEverything,0);
This builds a filter for category 0 that collides with everything.
Great!
Doing exactly this worked. That was easier than expected
Thank you
|