About PinConstraint Scripting - 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: About PinConstraint Scripting (/thread-391.html) |
About PinConstraint Scripting - Cannias - 21-02-2018 Hey there! I want to snap the ObiRope to the block i have in scene in runtime. I can snap one end of the ObiRope but the other end of ObiRope doesn't seem to be working i simply check for conditions (collider trigger, onMouseUp, etc.) and remove the PinConstraint from Spheres then add new PinConstraint to the block As you can see in the video, white sphere (which is Pinned to the first particle) does what i want but the black one doesn't. I can't get the last particle of ObiRope. Here's my code for snapping: Code: int addIndex; //Index of particle which i add PinConstraint (to block) Thanks in advance! RE: About PinConstraint Scripting - josemendez - 22-02-2018 (21-02-2018, 09:49 PM)Cannias Wrote: Hey there! last particle addIndex should be obiRope.UsedParticles-1. Arrays run from 0 to size-1 cheers! RE: About PinConstraint Scripting - Cannias - 22-02-2018 (22-02-2018, 08:58 AM)josemendez Wrote: last particle addIndex should be obiRope.UsedParticles-1. Arrays run from 0 to size-1 Hi josemendez, I did what you told me to do. It's now obiRope.UsedParticles-1. As you can see in this video, it works perfect for 6 particles (as Rope Length). But less than 6 particles, the rope behaves different which i couldn't understand. And for greater than 6 particles, it behaves exact same as 7 particles rope. I'm going out of my mind, help please P.S. I have a prefab which contains the obiRope, WhiteSphere and the BlackSphere. As in prefab, spheres are pinned to the ends of the rope. And I have a script called MovePin. So the moving spheres with mouse, changing rope length due to distance between two spheres, changing rope UV scale and snapping rope ends to the block stuffs are made in MovePin script. And i have the script on both of spheres and each one works for itself. Maybe knowing that could help you figure out what's the problem. Thanks in advance! RE: About PinConstraint Scripting - josemendez - 22-02-2018 (22-02-2018, 07:50 PM)Cannias Wrote: Hi josemendez, Hi, If you're changing the rope lenght at runtime using ObiRopeCursor, keep in mind that you're adding particles mid-rope (or wherever the cursor is). So of course the most recently added particle is not at the end or the beginning of the rope!. UsedParticles-1 will become the most recently added particle, not the one at the end. What you need to do if you always want to get the first and last particle indices in a dynamically resized rope is to work with segments (distance constraints). They are always consecutive, the first particle in the first distance constraint will always be the particle at the beginning of the rope, and the last particle in the last distance constraint will be the particle at the end of the rope. Code: ObiDistanceConstraintBatch batch = rope.DistanceConstraints.GetFirstBatch(); // or GetBatches()[0] for pre-3.3 RE: About PinConstraint Scripting - Cannias - 22-02-2018 (22-02-2018, 08:20 PM)josemendez Wrote: Hi, i love you! i love you! i love you! i love you! i love you! i love you! i love you! i love you! i love you! i love you! i love you! thank you sooooooooooooooooooooooooooooooooooooooooooooo muuchhhhhh!!!!! |