Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Help  Some questions & requests
#8
(08-08-2022, 09:46 AM)landosilva Wrote: Hey! Thank you again!

I tested your code with some modifications to be more similar to what I have and I'm having the same problem!
The key to reproduce the issue is:
  1. Use the same rope that was previously attached to something. In your example you are using new ones instead of reusing them.
  2. Move the attachments around.
Here's a video using your example:
https://streamable.com/675qmg

Here's a Unity Package with my modifications:
https://drive.google.com/file/d/1myw95Hj...sp=sharing

Please let me know if I'm doing something that I shouldn't!

Hi!

Attachments do not attach the rope to a point, they attach it to a target object. If you do this:

Code:
sameTargetItAlreadyHas.position = RandomPos;
rope.solver.positions[index] = sameTargetItAlreadyHas.position;
attachment.target = sameTargetItAlreadyHas;

The attachment is always active and its target object never actually changes. This line:
Code:
rope.solver.positions[index] = sameTargetItAlreadyHas.position;

Will have no effect since the -still active- attachment will regard it as a violation of the attachment constraint: "hey, something or someone has moved the rope away from where it should be attached!" and immediately enforce the constraint by setting the particle position back to its original value. Since the target object had moved around while the rope was inactive, but attachments always interpret positions as relative to the target, the rope is kept attached at its original point relative to the target's new position. From the manual:

Quote:It's important to realize that attachments do not move the particle group to the position of the target object, nor the target object to the position of the particle group. Moving the particle group to the target's position would collapse all particles into a single point, and would result in a kickback effect once the particles spring back to their original positions. Moving the target could cause a whole palette of issues depending on your game logic.

Instead, particles in the group are attached at their current position relative to the target object.


The solution is simple: disable the attachment when the rope is unused, re-enable the attachment when the rope gets reused. This way, the attachment knows that the it should re-attach the rope in its new position relative to the target object.

In the RopeAttach.cs script, add a new Disconnect() method and modify Connect():

Code:
public void Connect(Transform origin, Transform end)
    {
        attachment1.target = origin;
        attachment2.target = end;
        attachment1.enabled = true;
        attachment2.enabled = true;
    }

    public void Disconnect()
    {
        attachment1.enabled = false;
        attachment2.enabled = false;
    }

In RopePool.cs Update() method, add a new line at the else clause:

Code:
else
{
      //disconnect the rope before deactivating it.
      currentRope.GetComponent<RopeAttach>().Disconnect();

      currentRope.SetActive(false);
      currentRope.transform.SetParent(null);
      currentRope = null;
}
Reply


Messages In This Thread
Some questions & requests - by landosilva - 04-08-2022, 10:58 PM
RE: Some questions & requests - by josemendez - 05-08-2022, 07:57 AM
RE: Some questions & requests - by landosilva - 05-08-2022, 03:34 PM
RE: Some questions & requests - by josemendez - 05-08-2022, 04:17 PM
RE: Some questions & requests - by landosilva - 06-08-2022, 02:59 PM
RE: Some questions & requests - by josemendez - 08-08-2022, 07:44 AM
RE: Some questions & requests - by landosilva - 08-08-2022, 09:46 AM
RE: Some questions & requests - by josemendez - 08-08-2022, 10:54 AM
RE: Some questions & requests - by landosilva - 08-08-2022, 02:09 PM
RE: Some questions & requests - by josemendez - 08-08-2022, 02:24 PM
RE: Some questions & requests - by landosilva - 08-08-2022, 02:56 PM
RE: Some questions & requests - by josemendez - 08-08-2022, 03:21 PM
RE: Some questions & requests - by landosilva - 08-08-2022, 03:44 PM
RE: Some questions & requests - by josemendez - 08-08-2022, 03:46 PM
RE: Some questions & requests - by landosilva - 09-08-2022, 04:51 PM
RE: Some questions & requests - by josemendez - 10-08-2022, 07:18 AM
RE: Some questions & requests - by landosilva - 10-08-2022, 10:03 AM
RE: Some questions & requests - by josemendez - 10-08-2022, 10:15 AM
RE: Some questions & requests - by josemendez - 10-08-2022, 10:39 AM