Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Extend a rope when the attached object shot from a position
#11
(29-09-2022, 10:17 AM)josemendez Wrote: Hi,

You've created an empty particle group, hence the null ref exception: there's no particles in the group to copy to the attachment. You need to first specify which particles are part of the group. Like this:

Code:
var group = ScriptableObject.CreateInstance<ObiParticleGroup>();
group.particleIndices.Add(particleIndex); //<-- add at least one particle to the group.
_lastAttachment.particleGroup = group;

There's no need to give a name to the group or make it part of the blueprint unless you later want to retrieve it by name.

kind regards,

where particlesIndex is

Code:
var particleIndex = rope.solverIndices[rope.elements[rope.elements.Count - 1].particle2];

It is working as I see, but always have a very big gap between the body part and the rope's end
Reply
#12
(29-09-2022, 01:48 PM)lacasrac Wrote: where particlesIndex is

Code:
var particleIndex = rope.solverIndices[rope.elements[rope.elements.Count - 1].particle2];

That line doesn't make any sense, you're indexing the solverIndices array using the index of particles in the solver. For a single rope, this might work most of the time (even though particle order in the solver is undefined) but when there's more than 1 rope in the solver this will result in an out of bounds exception at runtime, because there's more particles in the solver than there are in a single actor.

Elements contain indices of particles in the solver, not the actor. Quoting the manual:

Quote:Each element in the array contains the indices of two particles in the solver: particle1 and particle2.

Particle groups however, reference particles in the actor (see: http://obi.virtualmethodstudio.com/manua...ments.html) since -unlike elements- they do exist even if the actor is not being simulated by a solver.

So if you wish to retrieve the last particle in a rope and create a particle group out of it, you need to do this:

Code:
// retrieve the solver index of the last particle in the rope:
var solverIndex = rope.elements[rope.elements.Count - 1].particle2;

// find out the index of that particle in the rope:
var particleIndex = rope.solver.particleToActor[solverIndex].indexInActor;

// add it to the group:
group.particleIndices.Add(particleIndex);

(29-09-2022, 01:48 PM)lacasrac Wrote: It is working as I see, but always have a very big gap between the body part and the rope's end

Make sure the particle is placed at the correct position at the time of creating the attachment (note that attachments do not teleport the particles in the group to any specific position, they keep their current positions relative to the object they're attached to), and that no collisions are taking place between the rope and the body part.

Also keep in mind that using interpolation in the solver will introduce a 1-frame delay in rendering, so unless your rigidbodies are also using interpolation you should set this setting to "none". Otherwise the rope will lag behind the rigidbodies it is attached to.
Reply
#13
(29-09-2022, 02:29 PM)josemendez Wrote: That line doesn't make any sense, you're indexing the solverIndices array using the index of particles in the solver. For a single rope, this might work most of the time (even though particle order in the solver is undefined) but when there's more than 1 rope in the solver this will result in an out of bounds exception at runtime, because there's more particles in the solver than there are in a single actor.

Elements contain indices of particles in the solver, not the actor. Quoting the manual:


Particle groups however, reference particles in the actor (see: http://obi.virtualmethodstudio.com/manua...ments.html) since -unlike elements- they do exist even if the actor is not being simulated by a solver.

So if you wish to retrieve the last particle in a rope and create a particle group out of it, you need to do this:

Code:
// retrieve the solver index of the last particle in the rope:
var solverIndex = rope.elements[rope.elements.Count - 1].particle2;

// find out the index of that particle in the rope:
var particleIndex = rope.solver.particleToActor[solverIndex].indexInActor;

// add it to the group:
group.particleIndices.Add(particleIndex);


Make sure the particle is placed at the correct position at the time of creating the attachment (note that attachments do not teleport the particles in the group to any specific position, they keep their current positions relative to the object they're attached to), and that no collisions are taking place between the rope and the body part.

Also keep in mind that using interpolation in the solver will introduce a 1-frame delay in rendering, so unless your rigidbodies are also using interpolation you should set this setting to "none". Otherwise the rope will lag behind the rigidbodies it is attached to.


Ok at the 100th experiment, this is sometimes working, sometimes not Gran sonrisa 70% working and very accurate...but sometimes just appears that gap. Interpolation is set to none...
But I don't know why. Gran sonrisa
Reply
#14
(29-09-2022, 04:41 PM)lacasrac Wrote: Ok at the 100th experiment, this is sometimes working, sometimes not Gran sonrisa 70% working and very accurate...but sometimes just appears that gap. Interpolation is set to none...
But I don't know why. Gran sonrisa

Also only works sometimes on the head. So more gap is in the legs and arms. I just searching the reasons why.
Reply
#15
(29-09-2022, 02:29 PM)josemendez Wrote: That line doesn't make any sense, you're indexing the solverIndices array using the index of particles in the solver. For a single rope, this might work most of the time (even though particle order in the solver is undefined) but when there's more than 1 rope in the solver this will result in an out of bounds exception at runtime, because there's more particles in the solver than there are in a single actor.

Elements contain indices of particles in the solver, not the actor. Quoting the manual:


Particle groups however, reference particles in the actor (see: http://obi.virtualmethodstudio.com/manua...ments.html) since -unlike elements- they do exist even if the actor is not being simulated by a solver.

So if you wish to retrieve the last particle in a rope and create a particle group out of it, you need to do this:

Code:
// retrieve the solver index of the last particle in the rope:
var solverIndex = rope.elements[rope.elements.Count - 1].particle2;

// find out the index of that particle in the rope:
var particleIndex = rope.solver.particleToActor[solverIndex].indexInActor;

// add it to the group:
group.particleIndices.Add(particleIndex);


Make sure the particle is placed at the correct position at the time of creating the attachment (note that attachments do not teleport the particles in the group to any specific position, they keep their current positions relative to the object they're attached to), and that no collisions are taking place between the rope and the body part.

Also keep in mind that using interpolation in the solver will introduce a 1-frame delay in rendering, so unless your rigidbodies are also using interpolation you should set this setting to "none". Otherwise the rope will lag behind the rigidbodies it is attached to.


OK I found my bug, thanks for the info Jose!
Reply