07-03-2018, 05:35 PM
(This post was last modified: 07-03-2018, 06:47 PM by ibbybn.
Edit Reason: workaround
)
Here's my current code to change the pinconstraints during runtime:
It works fine as long as one object I attach them to is kinematic for particles but as soon as I want both objects to be non kinematic in the rigidbody and in the obirigidbody the particles don't follow the object anymore. Not sure what I'm doing wrong right now?
Btw, there was also an error when attaching from the Rigidbody about it's velocities beeing set to NaNs.
I added a float.isNan check in the ObiRigidbody to get rid of it.
Using 3.3.1 with Unity 2017.3
Just found a workaround:
Making one of the objects kinematic for particles when adding the pinconstraints then afterwards make it nonkinematic. Still a bit odd that you need to trick it like this?
EDIT:
Actually that workaround only works sometimes?
Also just found out it doesn't happen in a scene with just two spheres with the same script etc.. so still bug hunting.
EDIT2:
Ok the problem was that I used ObiColliders as pintargets which were slightly inside another ObiCollider with a coll layer which the solver takes into account.
Apparently the solver tries to solve this for a second and then stops.
Code:
rope.PinConstraints.RemoveFromSolver (null);
ObiDistanceConstraintBatch distConstraints = rope.DistanceConstraints.GetFirstBatch ();
ObiPinConstraintBatch pinConstraints = rope.PinConstraints.GetFirstBatch ();
pinConstraints.Clear ();
Oni.SetParticlePositions (
rope.Solver.OniSolver,
new Vector4[] { new Vector4 (SubStart.transform.position.x, SubStart.transform.position.y, SubStart.transform.position.z, 1) },
1,
distConstraints.springIndices[0]
);
pinConstraints.AddConstraint (distConstraints.springIndices[0], SubStart.GetComponent<ObiColliderBase> (), Vector3.zero, 1);
Oni.SetParticlePositions (
rope.Solver.OniSolver,
new Vector4[] { new Vector4 (contactPoint.x, contactPoint.y, contactPoint.z, 1) },
1,
distConstraints.springIndices[distConstraints.springIndices.Count - 1]
);
pinConstraints.AddConstraint (distConstraints.springIndices[distConstraints.springIndices.Count - 1], Obj.GetComponent<ObiColliderBase> (), Vector3.zero, 1);
rope.PinConstraints.AddToSolver (null);
It works fine as long as one object I attach them to is kinematic for particles but as soon as I want both objects to be non kinematic in the rigidbody and in the obirigidbody the particles don't follow the object anymore. Not sure what I'm doing wrong right now?
Btw, there was also an error when attaching from the Rigidbody about it's velocities beeing set to NaNs.
I added a float.isNan check in the ObiRigidbody to get rid of it.
Using 3.3.1 with Unity 2017.3
Just found a workaround:
Making one of the objects kinematic for particles when adding the pinconstraints then afterwards make it nonkinematic. Still a bit odd that you need to trick it like this?
EDIT:
Actually that workaround only works sometimes?
Also just found out it doesn't happen in a scene with just two spheres with the same script etc.. so still bug hunting.
EDIT2:
Ok the problem was that I used ObiColliders as pintargets which were slightly inside another ObiCollider with a coll layer which the solver takes into account.
Apparently the solver tries to solve this for a second and then stops.