Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Dragging the edge of a rope
#1
Hey there,

I'd like to be able to have the edge of a rope move as the user drags the mouse cursor.

I tried doing this with a blueprint but I had two issues:

1. The blueprint got permanently changed.
2. The effect wasn't visible in the game in real-time, instead it was just visible in the editor, and the next time I ran the game.

Am I missing something? Is there a better way?

Here's the relevant code segment: 
Code:
ObiWingedPoint point = rope.ropeBlueprint.path.points[0];
point.position = worldMousePosition;
rope.ropeBlueprint.path.points[0] = point;

Many thanks.
Reply
#2
Hi there!

Blueprints are assets -just like textures, audio, animations or meshes, all stored in disk- that are used to generate a rope at runtime. They behave like prefabs: once the rope is instantiated from the blueprint, it is no longer tied to it. So modifying the blueprint will A) modify the blueprint permanently, since it's stored in disk, not memory B) have no effect on existing ropes at runtime.

Think of blueprints as a "mold" for making plastic figures: if you pour molten plastic on the mold, make a figure with it and afterwards modify the mold, the figure you've already created will remain unchanged. Changes to the mold will only affect figures you create from that point on.

See the "architecture" page of the manual for details: http://obi.virtualmethodstudio.com/manua...cture.html

If you want to drag the rope around, you need to move the rope itself, not the blueprint. Ropes -like any object in Obi- are made of particles, hence you want to use the particle API to modify them:
http://obi.virtualmethodstudio.com/manua...icles.html

You might want to try the utility ObiParticleDragger component. It uses the particle API to for a basic implementation of mouse-based click and drag. You can either use the component as-is if it meets your needs, or use it as a basis to build custom interaction.
Reply
#3
(22-12-2021, 12:08 PM)josemendez Wrote: Hi there!

Blueprints are assets -just like textures, audio, animations or meshes, all stored in disk- that are used to generate a rope at runtime. They behave like prefabs: once the rope is instantiated from the blueprint, it is no longer tied to it. So modifying the blueprint will A) modify the blueprint permanently, since it's stored in disk, not memory B) have no effect on existing ropes at runtime.

Think of blueprints as a "mold" for making plastic figures: if you pour molten plastic on the mold, make a figure with it and afterwards modify the mold, the figure you've already created will remain unchanged. Changes to the mold will only affect figures you create from that point on.

See the "architecture" page of the manual for details: http://obi.virtualmethodstudio.com/manua...cture.html

If you want to drag the rope around, you need to move the rope itself, not the blueprint. Ropes -like any object in Obi- are made of particles, hence you want to use the particle API to modify them:
http://obi.virtualmethodstudio.com/manua...icles.html

You might want to try the utility ObiParticleDragger component. It uses the particle API to for a basic implementation of mouse-based click and drag. You can either use the component as-is if it meets your needs, or use it as a basis to build custom interaction.


Thank you Jose, this is very helpful.

I was able to make this work according to your advice, and I was also able to hook to a "ripping" even I made in which I'd like the rope to follow the mouse cursor.

My idea was to make it follow the mouse by changing one of the Particle Attachments to a Transform that is moving in the scene according to the mouse position. I got it partially working, but the issue is that while the rope is moving according to this moving transform, it's not really connected to it, there's quite a significant margin for it's connection. Shouldn't the rope actually connect to that transform?

See a video that shows the current behavior:

https://drive.google.com/file/d/1qjAzto0...sp=sharing

Thanks!
Reply
#4
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.
Reply
#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