Posts: 5
Threads: 2
Joined: Jul 2019
Reputation:
0
Hello,
I am sorry if this question has already been answered, I did a search, but I gave up after the 4th page, maybe my search keyword wasn't good enough.
The question is simple: Is it possible to assign a handle manually?
Example: I select a particle and "create handle" this will create a new handle in the hierarchy.
But while doing tests, I re-initialize my rope multiple times and each time I have to create a new handle (and delete the previous one). Because I can't find a way to assign a particle to a handle manually.
I'm probably blind but I have no idea where this handle reference is made. It doesn't appear in Pin Constrains, neither on the handle component itself, and I can't find it anywhere in the different rope components.
Also that is something I wondered in the case I want two ropes to have one particle attached to the same handle. Is it possible (I know I can do it in other ways, such as pin constraint, but that handle system is so easy and simple to manage.. also I don't have to worry about collision problems with this system)
Thanks by advance
Posts: 6,346
Threads: 24
Joined: Jun 2017
Reputation:
400
Obi Owner:
05-07-2019, 08:23 AM
(This post was last modified: 05-07-2019, 08:24 AM by josemendez.)
(04-07-2019, 10:25 PM)Necka Wrote: Hello,
I am sorry if this question has already been answered, I did a search, but I gave up after the 4th page, maybe my search keyword wasn't good enough.
The question is simple: Is it possible to assign a handle manually?
Example: I select a particle and "create handle" this will create a new handle in the hierarchy.
But while doing tests, I re-initialize my rope multiple times and each time I have to create a new handle (and delete the previous one). Because I can't find a way to assign a particle to a handle manually.
I'm probably blind but I have no idea where this handle reference is made. It doesn't appear in Pin Constrains, neither on the handle component itself, and I can't find it anywhere in the different rope components.
Also that is something I wondered in the case I want two ropes to have one particle attached to the same handle. Is it possible (I know I can do it in other ways, such as pin constraint, but that handle system is so easy and simple to manage.. also I don't have to worry about collision problems with this system)
Thanks by advance
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.
Posts: 5
Threads: 2
Joined: Jul 2019
Reputation:
0
(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...
Posts: 6,346
Threads: 24
Joined: Jun 2017
Reputation:
400
Obi Owner:
05-07-2019, 02:17 PM
(This post was last modified: 05-07-2019, 02:18 PM by josemendez.)
(05-07-2019, 01:23 PM)Necka Wrote: 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.
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...
Hi,
In editor, handles are created from the particle editor (ObiParticleActorEditor.cs, "DrawFixControls" method). It basically does the same thing I posted previously: create a new GameObject, add a ObiHandle, and add the selected particles to it.
Quote: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?
When tearing/changing the length of a rope, particle ordering changes, however constraint ordering does not. There's several methods in the rope actor that let you get info about structural constraints (which for ropes are distance constraints, and for rods are stretch/shear constraints), and the particles they're affecting. So if you grab the second particle of the last constraint, that would be the last particle in the rope.
Anyway, this is not at all necessary for what you want to do, I think. ObiCursor can change the length of a rope by adding/removing rope from any point in the rope, in both directions. So simply place the cursor before the end of the rope. If the last particle is part of a handle, it will be preserved when changing rope length. See:
http://obi.virtualmethodstudio.com/tutor...ursor.html
|