Obi Official Forum
Connect two objects - 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: Connect two objects (/thread-215.html)



Connect two objects - elfinik - 27-10-2017

Hello.
I'm doing the game using obi physics, but after studying the documentation, I could not connect the two objects with a rope with the result I needed.

I need to connect two points so that when the platform bends turned, the cube falls forward. I tried to adjust the distance, mass and stuff, but nothing happened.

Points are selected through the script


Code:
     localOPB.AddConstraint(0, firstTarget.GetComponent<ObiCollider>(), firstTarget.InverseTransformPoint(firstPoint), 0);


Code:
    localOPB.AddConstraint(105, secondTarget.GetComponent<ObiCollider>(), secondTarget.InverseTransformPoint(secondPoint), 0);


[Image: 737fa4f5889a5ab1c6d8ac41d1c43587.png]


RE: Connect two objects - josemendez - 27-10-2017

(27-10-2017, 12:40 PM)elfinik Wrote: Hello.
I'm doing the game using obi physics, but after studying the documentation, I could not connect the two objects with a rope with the result I needed.

I need to connect two points so that when the platform bends turned, the cube falls forward. I tried to adjust the distance, mass and stuff, but nothing happened.

Points are selected through the script




Code:
     localOPB.AddConstraint(0, firstTarget.GetComponent<ObiCollider>(), firstTarget.InverseTransformPoint(firstPoint), 0);


Code:
    localOPB.AddConstraint(105, secondTarget.GetComponent<ObiCollider>(), secondTarget.InverseTransformPoint(secondPoint), 0);


[Image: 737fa4f5889a5ab1c6d8ac41d1c43587.png]

Hi!

How are you updating the constraints? Are you adding them back to the solver after adding new constraints to the pin constraints batch? You must follow this pattern:



Code:
ObiPinConstraints constraints = rope.PinConstraints;
ObiPinConstraintBatch batch = (ObiPinConstraintBatch)constraints.GetBatches()[0];

// remove the constraints from the solver, because we cannot modify the constraints list while the solver is using it.
constraints.RemoveFromSolver(null);

// your code to add new constraints to the batch

// add all constraints back:
constraints.AddToSolver(null);



RE: Connect two objects - elfinik - 30-10-2017

My problem is that I can not achieve the desired result. If the cube's mass is too small, the cube falls at the moment of connection. If the mass of the cube is larger, then it does not budge, even if the platform falls down and swings like a pendulum.

The rope is disabled and turned on after adding new points.

My code:


Code:
ObiPinConstraintBatch localOPB = new ObiPinConstraintBatch(false, false);
        localOPB.AddConstraint(0, firstTarget.GetComponent<ObiCollider>(), firstTarget.InverseTransformPoint(firstPoint), 0);
        localOPB.AddConstraint(105, secondTarget.GetComponent<ObiCollider>(), secondTarget.InverseTransformPoint(secondPoint), 0);
        localOPB.minYoungModulus = 0;
        localOPB.maxYoungModulus = 200;
        ObiConstraintBatch localOCB = rope.PinConstraints.GetBatches()[0];
        rope.PinConstraints.RemoveFromSolver(null);

        rope.PinConstraints.AddBatch(localOPB);

        rope.PinConstraints.AddToSolver(null);

        rope.PinConstraints.SetActiveConstraints();


        rope.DistanceConstraints.RemoveFromSolver(null);
        rope.BendingConstraints.RemoveFromSolver(null);
        rope.BendingConstraints.AddToSolver(rope);
        rope.DistanceConstraints.AddToSolver(rope);


        rope.BendingConstraints.SetActiveConstraints();

        rope.Solver.UpdateActiveParticles();



RE: Connect two objects - josemendez - 31-10-2017

Hi, 

You don't need to create a new batch to put constraints in. By default, an empty pin constraints batch already exists. Also, these lines do nothing:

rope.DistanceConstraints.RemoveFromSolver(null);

rope.BendingConstraints.RemoveFromSolver(null);
rope.BendingConstraints.AddToSolver(rope);
rope.DistanceConstraints.AddToSolver(rope);


You're removing the constraints, then adding back the exact same set of constraints, which does nothing.


I don't think I quite understand the scene setup you're aiming for. The top-left cube is supposed to be attached to the rope, but when is it supposed to fall?