Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Handles in runtime
#1
Exclamación 
Hey guys! I try to control the end of the rope i created in runtime. Now i want to move it by dragging. I decided to add a handle at the last particle of the rope and move it. But i don't know how to add a handle at the last particle just after i generate the rope in runtime. Help ASAP please? Thanks in advance!
Reply
#2
(09-02-2018, 12:17 PM)Cannias Wrote: Hey guys! I try to control the end of the rope i created in runtime. Now i want to move it by dragging. I decided to add a handle at the last particle of the rope and move it. But i don't know how to add a handle at the last particle just after i generate the rope in runtime. Help ASAP please? Thanks in advance!

Hi Cannias,

We've moved the thread to the correct sub forum (Obi Rope) hope you don't mind.
Regarding your question, just use the AddParticle method of the ObiHandle class and pass the index/position/mass of the appropriate particle. Like this:

Code:
// create a new handle (optional: position the handle anywhere you want by setting transform.position):
GameObject c = new GameObject("Obi Handle");
ObiParticleHandle handle = c.AddComponent<ObiParticleHandle>();
handle.Actor = rope;

// Add the last particle in the rope:
int index = rope.UsedParticles-1;
handle.AddParticle(index,rope.transform.TransformPoint(rope.positions[index]),rope.invMasses[index]);

Imho this is way too complex for your purpose tough. It will be much easier to simply set the particle position as long as the user keeps the button pressed. Since you are dealing with a single particle at a time, you do not need a persistent transform (which is what a handle is) and you don't have to deal with local/world space conversions: everything is kept in world space:

Code:
Oni.SetParticlePositions(rope.Solver.OniSolver,new Vector4[]{position},1,rope.particleIndices[rope.UsedParticles-1]);

This will allow you to move any particle in the rope, not just the ends, not just the ones that are fixed. Note that you can fix a particle in place by setting its inverse mass to zero by using Oni.SetParticleInverseMasses in a similar fashion.

See: http://obi.virtualmethodstudio.com/tutor...icles.html
Reply
#3
(09-02-2018, 12:57 PM)Hi josemendez,Thanks for reply. But what should i code instead of "position" here? Wrote:
Code:
Oni.SetParticlePositions(rope.Solver.OniSolver,new Vector4[]{position},1,rope.particleIndices[rope.UsedParticles-1]);
Reply
#4
Hi Cannias,

A Vector4 containing the position you want to place the particle at. Like this: new Vector4(x,y,z,0).
Reply
#5
Is there an equivalent for this in the current version? All of the documentation I can find is out of date and obi handles aren't a thing anymore, nor is the option to set individual particle positions manually. I have a rope that is being grabbed at one end so I want the loose end to respond to physics, but the grabbed end to stay attached to the hand which is moved in update. Currently, if I use the fixed updater, the grabbed end is floaty and disconnects from the hand, but if I use late updater it jitters. I want it to not simulate physics on the grabbed particle while still doing so on the rest of the particles and I need this to be dynamic because the rope could be grabbed from either end or not at all.
Reply
#6
(22-07-2024, 10:26 AM)Fuzzypeg Wrote: Is there an equivalent for this in the current version? All of the documentation I can find is out of date and obi handles aren't a thing anymore

This is the documentation for the latest version:
http://obi.virtualmethodstudio.com/manual/6.3/

Handles were replaced by static attachments in Obi 4.0. Functionally they do the exact same thing.

(22-07-2024, 10:26 AM)Fuzzypeg Wrote: nor is the option to set individual particle positions manually.

Disable the attachment, set the particle positions, then re-enable it. There's sample code for this in the manual, that forces particles to attach to a specific local position in the target transform:
http://obi.virtualmethodstudio.com/manua...ments.html

(22-07-2024, 10:26 AM)Fuzzypeg Wrote: I have a rope that is being grabbed at one end so I want the loose end to respond to physics, but the grabbed end to stay attached to the hand which is moved in update. Currently, if I use the fixed updater, the grabbed end is floaty and disconnects from the hand, but if I use late updater it jitters.

This doesn't have anything to do with the attachment itself, but with the order in which Unity calls its events. By default Obi's physics engine (and attachments, since they're part of the engine) are updated in FixedUpdate(). If you update the hand in Update (which takes place after FixedUpdate) there will be a one frame delay between the hand and the rope, since the simulation works with transform data that is one frame old. If you use LateUpdate, it will jitter since it uses a variable timestep instead of a fixed timestep (which is what FixedUpdate is for in Unity).

Maybe you want to update the hand's transform in ObiSolver.OnBeginStep instead, so that it takes place before each physics update? This would solve both of the above issues.

(22-07-2024, 10:26 AM)Fuzzypeg Wrote: I want it to not simulate physics on the grabbed particle while still doing so on the rest of the particles

Physics are not simulated for particles handled by a static attachment. Their mass is set to infinite and their position follows the target transform. All other particles have their physical simulation updated as usual.

(22-07-2024, 10:26 AM)Fuzzypeg Wrote: and I need this to be dynamic because the rope could be grabbed from either end or not at all.

You can create/destroy attachments at runtime just fine, see:
http://obi.virtualmethodstudio.com/manua...ments.html

let me know if I can be of further help,

kind regards
Reply
#7
Thanks for the reply, I get the feeling I have maybe been thinking about this a little sideways. I'll have a read through everything linked and see if I can get a better handle on things.
Reply