Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Help  Ropes // Couple of questions
#3
(11-05-2023, 10:22 AM)josemendez Wrote: Hi!

You can create particle groups at runtime, in addition to the ones automatically created when generating the blueprint (one per control point). The manual shows some sample code to do this:

Code:
var group = ScriptableObject.CreateInstance<ObiParticleGroup>();
group.particleIndices.Add(particleIndex); // index of the particle in the actor
attachment.particleGroup = group;

let me know if you need further help,

kind regards


Hi Jose, 

Thanks for your reply.
With your information I got it to work with the following code.
Do you maybe see anything that might cause a problem or that i'm using in a wrong way?

Code:
void AddControllPoint(int index)
    {
        var group = ScriptableObject.CreateInstance<ObiParticleGroup>(); //Create a particle group
        group.particleIndices.Add(index); // index of the particle in the actor

        int pickedParticle = rope.elements[index].particle2; //store particle index
        var particlePos = rope.solver.positions[pickedParticle]; //store the position of the particle
        attObject.transform.localPosition = particlePos; //Move the attachment object to the stored particles location

        var attachment = actor.AddComponent<ObiParticleAttachment>(); //Create an Attachment component
        attachment.target = attObject.transform; //add an object as target in the Attachment component
        attachment.particleGroup = group; //Assign the particle group to the target

        addControlPoint = false;
        Debug.Log("Control Point Created");
    }

Besides this I'm still wondering if you could help me with how to visualize the particles.
The only way I get to see the particles is when using ObiInstancedParticleRenderer and disabeling the mesh renderer of the rope.
Is that the only way to visualize the particles or am I missing something in the ObiParticleRenderer component?

Thanks again for your help and I'm a step closer once again Sonrisa

Kind regards, 

Patrick


EDIT:
I think I cheered a bit to early haha.
The script seems to work perfectly for a rope that keeps its original blueprint (first attachment).
But after I extended the rope during runtime and I want to add a attachment the object goes to the correct transform (at least it acts the way I expect it to act) but the particle it's attached to seems to be off (or the other way around) 

In the 2nd attachment you can see the cube is placed somewhere along the rope but when I move the cube around it's attached to the wrong (?) particle. 
Yesterday I only tested it with the original blueprint and not after the rope is extended during runtime. 

Does this maybe have to do with the allocation of particles during runtime? (http://obi.virtualmethodstudio.com/manua...ropes.html)


Attached Files Thumbnail(s)
       
Reply


Messages In This Thread
Ropes // Couple of questions - by 5G_Zendmast - 04-05-2023, 10:05 AM
RE: Ropes // Couple of questions - by josemendez - 11-05-2023, 10:22 AM
RE: Ropes // Couple of questions - by 5G_Zendmast - 16-05-2023, 01:48 PM