Obi Official Forum
Help Rope static attachment seems to lag behind the moving object it's attached to - 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 Rope static attachment seems to lag behind the moving object it's attached to (/thread-4303.html)



Rope static attachment seems to lag behind the moving object it's attached to - ShawnF - 25-07-2024

You can see what I mean here: https://youtu.be/cMG1YjnYDwM

The rope has an attachment to the character's hand, but it follows a bit behind the char as you move.

Solver is on FixedUpdate, character is being moved through physical forces. Both the character and the rope have interpolate on.

Code for the attachment is here, in case there's something about the initial setup that's causing problems:

Code:
public void AttachParticle(RopeChar ropeChar, int particleIndex)
    {
        attachedRopeChar = ropeChar;

        // Create a new attachment and set it to be attached to the character's hand
        attachment = obiRope.gameObject.AddComponent<ObiParticleAttachment>(); 
        attachment.target = attachedRopeChar.attachTransform;
                   
        // Handle gameplay of attached char (swings from hinge, the rope is just visual and used for collision detection)
        attachedRopeChar.AttachToRope(this);

        // Move the collided particle to the char's hand pos
        UnityEngine.Vector3 relativePlayerPos = attachedRopeChar.attachTransform.position - solver.transform.position;
        solver.positions.SetVector3(particleIndex, relativePlayerPos);
   
        // Create a new particle group and assign it the particle that you collided with
        ObiSolver.ParticleInActor particleInActor = solver.particleToActor[particleIndex];
       
        ObiParticleGroup group = ScriptableObject.CreateInstance<ObiParticleGroup>();
        group.particleIndices.Add(particleInActor.indexInActor); // index of the particle in the actor
        attachment.particleGroup = group;
    }



RE: Rope static attachment seems to lag behind the moving object it's attached to - josemendez - 25-07-2024

(25-07-2024, 02:26 PM)ShawnF Wrote: You can see what I mean here: https://youtu.be/cMG1YjnYDwM

The rope has an attachment to the character's hand, but it follows a bit behind the char as you move.

Solver is on FixedUpdate, character is being moved through physical forces. Both the character and the rope have interpolate on.

Code for the attachment is here, in case there's something about the initial setup that's causing problems:

Code:
public void AttachParticle(RopeChar ropeChar, int particleIndex)
    {
        attachedRopeChar = ropeChar;

        // Create a new attachment and set it to be attached to the character's hand
        attachment = obiRope.gameObject.AddComponent<ObiParticleAttachment>(); 
        attachment.target = attachedRopeChar.attachTransform;
                   
        // Handle gameplay of attached char (swings from hinge, the rope is just visual and used for collision detection)
        attachedRopeChar.AttachToRope(this);

        // Move the collided particle to the char's hand pos
        UnityEngine.Vector3 relativePlayerPos = attachedRopeChar.attachTransform.position - solver.transform.position;
        solver.positions.SetVector3(particleIndex, relativePlayerPos);
   
        // Create a new particle group and assign it the particle that you collided with
        ObiSolver.ParticleInActor particleInActor = solver.particleToActor[particleIndex];
       
        ObiParticleGroup group = ScriptableObject.CreateInstance<ObiParticleGroup>();
        group.particleIndices.Add(particleInActor.indexInActor); // index of the particle in the actor
        attachment.particleGroup = group;
    }

Hi!

Solver should be using LateFixedUpdater, since you want the rope to use the position of the rigidbody *after* it has moved in FixedUpdate. Otherwise the rope will be one frame behind.

Let me know if I can be of further help,

kind regards


RE: Rope static attachment seems to lag behind the moving object it's attached to - ShawnF - 25-07-2024

Thanks for the quick reply - that solved my main issue!

However, I'm getting some weird little pops now at the end of the swing when the movement direction changes. Any thoughts on what might be causing that?
https://youtu.be/Joty-hJeaDY


Btw, I should mention that I put in your changes from this old post in order to add interpolation to the attachment and reduce jitter, which did help a lot, but there's just the above issue remaining: 
http://obi.virtualmethodstudio.com/forum/thread-3791-post-13995.html#pid13995


RE: Rope static attachment seems to lag behind the moving object it's attached to - ShawnF - 30-07-2024

Just wanted to bump this one since I think it fell through the cracks a bit. Any ideas?