Obi Official Forum
Help Finding last point of rope - Printable Version

+- Obi Official Forum (https://obi.virtualmethodstudio.com/forum)
+-- Forum: Obi Users Category (https://obi.virtualmethodstudio.com/forum/forum-1.html)
+--- Forum: Obi Rope (https://obi.virtualmethodstudio.com/forum/forum-4.html)
+--- Thread: Help Finding last point of rope (/thread-3177.html)

Pages: 1 2 3 4


Finding last point of rope - srid96 - 15-11-2021

Hi,

I need to find the last point of rope in script, not the particles(because when moving the rope, particles seems to be bit late to reach the rope rendered position.

I know this is basic ques, I have searched everywhere, I couldnt get what i need.


RE: Finding last point of rope - josemendez - 15-11-2021

(15-11-2021, 07:36 AM)srid96 Wrote: Hi,

I need to find the last point of rope in script, not the particles(because when moving the rope, particles seems to be bit late to reach the rope rendered position.

I know this is basic ques, I have searched everywhere, I couldnt get what i need.

Hi!

This is explained in the "scripting particles" section manual:
http://obi.virtualmethodstudio.com/manual/6.2/scriptingparticles.html

Quote:The solver will also generate renderable particle positions and orientations at the end of every frame. You can access them like this:

Vector3 pos = solver.renderablePositions[actor.solverIndices[0]];

If the solver's interpolation mode is set to "interpolate", solver.renderablePositions will contain temporally smoothed-out positions that won´t coincide with the actual particle positions at the end of the simulation step. That's why they are called "renderable": they are only used for smooth rendering, but they aren't fed back into the simulation.

let me know if you need further help. cheers!


RE: Finding last point of rope - srid96 - 15-11-2021

(15-11-2021, 08:40 AM)josemendez Wrote: Hi!

This is explained in the "scripting particles" section manual:
http://obi.virtualmethodstudio.com/manual/6.2/scriptingparticles.html


let me know if you need further help. cheers!
can you help me on how to get the last point on rope?


RE: Finding last point of rope - josemendez - 15-11-2021

(15-11-2021, 09:08 AM)srid96 Wrote: can you help me on how to get the last point on rope?

The manual explains how to get the position of any particle in the actor. The last one (or the first one, the 3rd one) is no different from any other. Instead of iterating trough all particles in the actor.solverIndices array, get the last one:

Code:
var lastPos = solver.renderablePositions[actor.solverIndices[actor.solverIndices.Length-1]];

Keep in mind that if you're tearing or resizing your rope at runtime, you will need to use rope elements to consistently get the last particle (as it will change at runtime). See the API docs for more info.


RE: Finding last point of rope - srid96 - 15-11-2021

(15-11-2021, 09:21 AM)josemendez Wrote: The manual explains how to get the position of any particle in the actor. The last one (or the first one, the 3rd one) is no different from any other. Instead of iterating trough all particles in the actor.solverIndices array, get the last one:

Code:
var lastPos = solver.renderablePositions[actor.solverIndices[actor.solverIndices.Length-1]];

Keep in mind that if you're tearing or resizing your rope at runtime, you will need to use rope elements to consistently get the last particle (as it will change at runtime). See the API docs for more info.
I did this, but my position seems to be somewhere other than end of the rope. I have attached for your reference. Let me know how to fix this.
Thank you.


RE: Finding last point of rope - josemendez - 15-11-2021

(15-11-2021, 03:35 PM)srid96 Wrote: I did this, but my position seems to be somewhere other than end of the rope. I have attached for your reference. Let me know how to fix this.
Thank you.

Hi,

Can't see any attached code/file to your post.


RE: Finding last point of rope - srid96 - 15-11-2021

(15-11-2021, 03:39 PM)josemendez Wrote: Hi,

Can't see any attached code/file to your post.
Sorry, i didnt know what happened.

(15-11-2021, 03:42 PM)srid96 Wrote: Sorry, i didnt know what happened.



RE: Finding last point of rope - josemendez - 15-11-2021

Positions (and all other particle data) in Obi are expressed in solver space:
http://obi.virtualmethodstudio.com/manual/6.2/scriptingparticles.html

Quote:All spatial properties (positions, orientations, velocities, vorticities, etc) are expressed in the solver's local space.

However you're assigning your position to transform.position, which is expressed in world space. If you want to use it this way, you need to convert the particle position to world space first, using Unity's TransformPoint(): https://docs.unity3d.com/ScriptReference/Transform.TransformPoint.html


RE: Finding last point of rope - srid96 - 16-11-2021

[attachment=1171 Wrote:[attachment=1170]josemendez pid='11140' dateline='1636987641']Positions (and all other particle data) in Obi are expressed in solver space:
http://obi.virtualmethodstudio.com/manual/6.2/scriptingparticles.html


However you're assigning your position to transform.position, which is expressed in world space. If you want to use it this way, you need to convert the particle position to world space first, using Unity's TransformPoint(): https://docs.unity3d.com/ScriptReference/Transform.TransformPoint.html
Hi, transforming to world space did not put the object to the last point on rope. Is there anything else am I missing from the attachments? 

 I also tried particle attachment of an object at the end of the rope (like in chains demo), i'm curious how that chainball moves smoothly and having mass of 5 units didnt jitter/dance where in my case i have to bring the mass to the lowest value to stop jittering and when moving rope , object is not moving smoothly like the chainball.
See the imgs below for particle attachments


RE: Finding last point of rope - josemendez - 16-11-2021

(16-11-2021, 08:30 AM)srid96 Wrote: Hi, transforming to world space did not put the object to the last point on rope. Is there anything else am I missing from the attachments? 

It should. That's all there is to it, transforming from solver to world space will give you the particle position in world space. Can you share the code you wrote to do this?

(16-11-2021, 08:30 AM)srid96 Wrote:  I also tried particle attachment of an object at the end of the rope (like in chains demo), i'm curious how that chainball moves smoothly and having mass of 5 units didnt jitter/dance where in my case i have to bring the mass to the lowest value to stop jittering and when moving rope , object is not moving smoothly like the chainball.

Mass is not the issue here, Obi is unconditionally stable so any jittering indicates a setup problem: probably your object is colliding with the rope. The object cannot be simultaneously inside and outside the rope (which is what the attachment and collisions want, respectively) so it "dances" between both configurations. If the rope needs to be attached inside of or very close to the object, simply disable collisions between the end of the rope and the collider. You can use filters for this.

This issue along with the solution is explained in the manual, at the end of the "pin constraints" section referenced from dynamic attachments:
http://obi.virtualmethodstudio.com/manual/6.2/pinconstraints.html