Posts: 44
Threads: 15
Joined: Dec 2020
Reputation:
0
Hi there,
I have a rope.
Is there a way to child a transform, renderer to the rope and specifuiclally a particle attachment so that this transform rednerer is always, whereever the selected particle attachment is, relative to its rope?
Basically, I would like a spehre to always be at the end of the rope.
Thanks
Posts: 6,347
Threads: 24
Joined: Jun 2017
Reputation:
400
Obi Owner:
09-08-2023, 07:11 AM
(This post was last modified: 09-08-2023, 07:12 AM by josemendez.)
(07-08-2023, 03:12 PM)Renman3000 Wrote: Hi there,
I have a rope.
Is there a way to child a transform, renderer to the rope and specifuiclally a particle attachment so that this transform rednerer is always, whereever the selected particle attachment is, relative to its rope?
Basically, I would like a spehre to always be at the end of the rope.
Thanks
Hi,
There's many ways to do this, depending on what you want exactly.
If you want to make sure a transform is always at the position of the last particle in the rope, you can just set the position of the transform to the position of the last particle:
Code: int lastParticle = rope.elements[rope.elements.Count-1].particle2;
transform.position = rope.solver.TransformPoint(rope.solver.positions[lastParticle]);
Another option is to retrieve the position of the last frame in the rope, which will provide you with orientation information as well. You do this by using
Code: var frame = rope.GetComponent<ObiPathSmoother>().GetSectionAt(1); // normalized coord from 0/start to 1/end
transform.position = frame.position;
transform.rotation = Quaternion.LookRotation(frame.tangent, frame.binormal);
A third option is to use the utility ObiRopeAttach component, which implements the second option (GetSectionAt) so you don't have to write it yourself.
kind regards,
Posts: 30
Threads: 9
Joined: Jul 2023
Reputation:
0
(09-08-2023, 07:11 AM)josemendez Wrote: Hi,
There's many ways to do this, depending on what you want exactly.
If you want to make sure a transform is always at the position of the last particle in the rope, you can just set the position of the transform to the position of the last particle:
Code: int lastParticle = rope.elements[rope.elements.Count-1].particle2;
transform.position = rope.solver.TransformPoint(rope.solver.positions[lastParticle]);
Another option is to retrieve the position of the last frame in the rope, which will provide you with orientation information as well. You do this by using
Code: var frame = rope.GetComponent<ObiPathSmoother>().GetSectionAt(1); // normalized coord from 0/start to 1/end
transform.position = frame.position;
transform.rotation = Quaternion.LookRotation(frame.tangent, frame.binormal);
A third option is to use the utility ObiRopeAttach component, which implements the second option (GetSectionAt) so you don't have to write it yourself.
kind regards, Cannot resolve symbol 'TransformPoint' - rope.solver.TransformPoint
Posts: 6,347
Threads: 24
Joined: Jun 2017
Reputation:
400
Obi Owner:
09-08-2023, 02:38 PM
(This post was last modified: 09-08-2023, 02:38 PM by josemendez.)
(09-08-2023, 12:23 PM)Alexander34 Wrote: Cannot resolve symbol 'TransformPoint' - rope.solver.TransformPoint
Sorry, typo. Should be rope.solver. transform. TransformPoint
Posts: 44
Threads: 15
Joined: Dec 2020
Reputation:
0
(09-08-2023, 07:11 AM)josemendez Wrote: Hi,
There's many ways to do this, depending on what you want exactly.
If you want to make sure a transform is always at the position of the last particle in the rope, you can just set the position of the transform to the position of the last particle:
Code: int lastParticle = rope.elements[rope.elements.Count-1].particle2;
transform.position = rope.solver.TransformPoint(rope.solver.positions[lastParticle]);
Another option is to retrieve the position of the last frame in the rope, which will provide you with orientation information as well. You do this by using
Code: var frame = rope.GetComponent<ObiPathSmoother>().GetSectionAt(1); // normalized coord from 0/start to 1/end
transform.position = frame.position;
transform.rotation = Quaternion.LookRotation(frame.tangent, frame.binormal);
A third option is to use the utility ObiRopeAttach component, which implements the second option (GetSectionAt) so you don't have to write it yourself.
kind regards, Thanks!
Posts: 44
Threads: 15
Joined: Dec 2020
Reputation:
0
11-08-2023, 04:33 PM
(This post was last modified: 11-08-2023, 04:34 PM by Renman3000.)
Hi there,
So a peculiar issue that I can not solve.
Code: Vector3 posEnd = obiRope.solver.positions[i_lastParticle];
So some background, this is running on an instance of my own Class, TentacleUnit, of which I have a half dozen in an array. Despite double-checking and rechecking that each instance of TentacleUnit is referencing its own obiRope, the position being reported is one position, across all units.
Is there any reason, you can think of where calling one instance of an obiRope.Solver would imply this across all?
Thanks
Posts: 6,347
Threads: 24
Joined: Jun 2017
Reputation:
400
Obi Owner:
(11-08-2023, 04:33 PM)Renman3000 Wrote: Hi there,
So a peculiar issue that I can not solve.
Code: Vector3 posEnd = obiRope.solver.positions[i_lastParticle];
So some background, this is running on an instance of my own Class, TentacleUnit, of which I have a half dozen in an array. Despite double-checking and rechecking that each instance of TentacleUnit is referencing its own obiRope, the position being reported is one position, across all units.
Is there any reason, you can think of where calling one instance of an obiRope.Solver would imply this across all?
Thanks
Hi!
Particle data is stored in the solver, for all actors in it. So if you're accessing the same particle index for all ropes, the position reported will be the same for all of them.
How are you calculating i_lastParticle for each rope?
kind regards,
Posts: 44
Threads: 15
Joined: Dec 2020
Reputation:
0
14-08-2023, 04:26 PM
(This post was last modified: 14-08-2023, 04:27 PM by Renman3000.)
(14-08-2023, 06:18 AM)josemendez Wrote: Hi!
Particle data is stored in the solver, for all actors in it. So if you're accessing the same particle index for all ropes, the position reported will be the same for all of them.
How are you calculating i_lastParticle for each rope?
kind regards,
Hi,
So a little confused in that, I was thinking that if I called via my own script, an instance of an ObiRope obiRopeX that by further calling obiRopeX.Solver.positions[i_lastParticleIndex], that this would generate the last particle attachment, particle group position, on obiRopeX.
If this is incorrect, how do I get a position of a Particle Attachment, Particle Group?
Thanks
Posts: 6,347
Threads: 24
Joined: Jun 2017
Reputation:
400
Obi Owner:
14-08-2023, 08:29 PM
(This post was last modified: 16-08-2023, 07:50 AM by josemendez.)
(14-08-2023, 04:26 PM)Renman3000 Wrote: Hi,
So a little confused in that, I was thinking that if I called via my own script, an instance of an ObiRope obiRopeX that by further calling obiRopeX.Solver.positions[i_lastParticleIndex], that this would generate the last particle attachment, particle group position, on obiRopeX.
Hi,
It entirely depends on the value of “i_lastParticleIndex”, that’s why I asked how you are calculating it. But in general no, rope.solver.positions contains all particles managed by that solver, not just the particles for one particular rope. See:
http://obi.virtualmethodstudio.com/manua...cture.html
http://obi.virtualmethodstudio.com/manua...icles.html
Quote:If this is incorrect, how do I get a position of a Particle Attachment, Particle Group?
Thanks
Particle, Particle group and Attachment are 3 completely different things. If you mean how to get the position of the last particle in the rope, you can use this snippet I suggested before:
Code: int lastParticleIndex = rope.elements[rope.elements.Count-1].particle2;
var position = rope.solver.transform.TransformPoint(rope.solver.positions[lastParticleIndex]);
If you're interested in particle groups instead, to get the index of a particle in a group you do:
Code: var group= rope.blueprint.groups[groupIndex];
int particleIndex = rope.solverIndices[group.particleIndices[0]]; // in a rope, all groups contain a single particle.
Using this index you can look up its position in the solver.positions array as well.
Attachments have no position, since they're just a constraint relationship between a particle group and a transform.
Posts: 44
Threads: 15
Joined: Dec 2020
Reputation:
0
15-08-2023, 04:24 PM
(This post was last modified: 16-08-2023, 07:49 AM by josemendez.)
(14-08-2023, 08:29 PM)josemendez Wrote: Hi,
It entirely depends on the value of “i_lastParticleIndex”, that’s why I asked how you are calculating it. But in general no, rope.solver.positions contains all particles managed by that solver, not just the particles for one particular rope. See:
http://obi.virtualmethodstudio.com/manua...cture.html
http://obi.virtualmethodstudio.com/manua...icles.html
Particle, Particle group and Attachment are 3 completely different things. If you mean how to get the position of the last particle in the rope, you can use this snippet I suggested before:
Code: int lastParticleIndex = rope.elements[rope.elements.Count-1].particle2;
var position = rope.solver.transform.TransformPoint(rope.solver.positions[lastParticleIndex]);
If you're interested in particle groups instead, to get the index of a particle in a group you do:
Code: var group= rope.blueprint.groups[groupIndex];
int particleIndex = rope.solverIndices[group.particleIndices[0]]; // in a rope, all groups contain a single particle.
Using this index you can look up its position in the solver.positions array as well.
Attachments have no position, since they're just a constraint relationship between a particle group and a transform.
Hi, so if you imagine a rope, with three particleAttachments, each with a unique particleGroup, where index 0 is left, index 1 is middle and index 2 is the right end of the rope.
I want to know the position that is, index 2.
|