Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Help  Assigning Obi Handle in Editor
#3
(05-07-2019, 08:23 AM)josemendez Wrote: Hi there,

First off, handles and pin constraints work in different ways and give different results, so they're often not interchangeable. Depending on what you need to do, you want to use one or   the other.

- Pin constraints establish a two-way connection between the rope and the object it is pinned to. This means that the rope will exert forces on the object, and vice versa. This allows you to hang objects from the rope, ie objects that can pull the rope and be pulled by it.

- Handles are simply a convenient way of "fixing" (freezing) a group of particles, and setting their positions so that they match a transform. This means the particles in the handle have their dynamics deactivated (not affected by gravity, external forces or constraints) and are simply moved by means of directly setting their position. Because of this, particles will simply move to where the handle tells them, will ignore any forces or constraints (that's why collisions do not affect them in any way) and will not extern any force on the handle or any object in the handle's hierarchy.

To assign a handle at runtime (i assume this is what you mean by "manually"), you simply  create a new GameObject, add the ObiHandle component to it. Handles have a very simple API: you can add particle indices to them, or remove particle indices from them. That's pretty much it:
http://obi.virtualmethodstudio.com/api.html

For instance, to create a handle that fixes the position of the first two particles in a cloth:

Code:
// Create a new game object and add the handle component:
GameObject obj = new GameObject("Obi Handle");
ObiParticleHandle handle = obj.AddComponent<ObiParticleHandle>();

// Add the first two particles to it:
handle.AddParticle(i, actor.GetParticlePosition(0),Quaternion.identity,actor.invMasses[0],0);
handle.AddParticle(i, actor.GetParticlePosition(1),Quaternion.identity,actor.invMasses[1],0);

Note that after re-initializing a rope, all the particles are created from scratch, so existing handles lose their references. You must re-create the handles after that.

Hello,

thank you very much for the detailled answer,

I was not speaking about runtime but in editor - I was expecting to see a line somewhere on one of the Rope components when selecting the particles pinned to a handle "This particle is pinned to that Handle" but that doesn't seem to appear in any inspector.

I think I'll go with a runtime solution then, it's more flexible. But I'm again very sorry for this, from the documentation I always find the way of selecting the first particles but in my case I need a handle to be attached at the end of the rope. Is there an easy way of selecting the last index of the particles?

And bonus question: I believe this won't work if I expend/retract the rope as the last particle will always be different, right?

For context: My player have some sort of tool weapon that has a rope (looking like a Laser) where the end of the rope is attached to the mouse position. I'm having a hard time as when the player equip the weapon, the rope goes crazy for a few frames (despite being super rigid and the distance constraint quite high). So I'm trying now to have the reel-in and out working but I need to get the last particles for the pin to work in that case...
Reply


Messages In This Thread
Assigning Obi Handle in Editor - by Necka - 04-07-2019, 10:25 PM
RE: Assigning Obi Handle in Editor - by Necka - 05-07-2019, 01:23 PM