Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Dragging the edge of a rope
#5
(23-12-2021, 04:42 PM)Sanppy Wrote: OK I think I made some progress. I understand now that in order for the attachment change to also work visually, in a sense of the rope to be visually attached to the new attachment, the transform must be first in the location of the relevant rope end. 

I'm able to bring the transform to the rope end, but that's not good enough for me as I want the rope to get to the transform actually.

Is there any easy way of moving a rope end to a transform and then immediately changing the attachment to that transform?
This whole thing of finding the rope end and moving it to the transform is proving to be a bit of a challenge for some reason.

Thanks.

OK I think I got this one done, eventually without taking the method of moving the rope particles, but still a good result.
So my issue was that when I was trying to move my transform to the end of the rope, before making the attachment switch, I couldn't really get the end position.

Finally I was able to get it with the following series of commands (it's an ugly piece of code before refactoring, but it should work):

Code:
//This is an empty game object that I keep on updating its position as the user holds the mouse button.
        GameObject tempMouseCursor = GameObject.Find("MousePosition");
        //I save its last position into a temporary vector3 variable.
        Vector3 mousePosition = tempMouseCursor.transform.position;
        
        //I get the particle attachment particle index, which I think is only applicable in the editor, and this is why it didn't work for me in run-time in previous attempts.
        int editorParticleIndex = obiRope.GetComponents<ObiParticleAttachment>()[1].particleGroup.particleIndices[0];
        // Using that editorParticleIndex, we're able to get the runtime index.
        int runtimeParticleIndex = obiRope.GetParticleRuntimeIndex(editorParticleIndex);

        //finally we're able to find its position.
        Vector3 particlePosition = obiRope.GetParticlePosition(runtimeParticleIndex);
        
        //we move our game object that represents the mouse courser to that particle location.
        tempMouseCursor.transform.position = particlePosition;
        // we make the attachment switch.
        obiRope.GetComponents<ObiParticleAttachment>()[1].target = tempMouseCursor.transform;
        //we move back our cursor to where the user held the mouse before.
        tempMouseCursor.transform.position = mousePosition;


Phew that one was tough. Happy that I seem to be done with it.
Reply


Messages In This Thread
Dragging the edge of a rope - by Sanppy - 22-12-2021, 12:00 PM
RE: Dragging the edge of a rope - by josemendez - 22-12-2021, 12:08 PM
RE: Dragging the edge of a rope - by Sanppy - 22-12-2021, 04:45 PM
RE: Dragging the edge of a rope - by Sanppy - 23-12-2021, 04:42 PM
RE: Dragging the edge of a rope - by Sanppy - 23-12-2021, 06:32 PM