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