06-03-2024, 11:21 AM
(This post was last modified: 06-03-2024, 11:30 AM by Alexander34.)
The problem is as follows: I have a code that creates a control point in the middle of the rope, then I create an attachment on the rope and attach it to the attraction point inside the object that I want to move with this rope. Since the attraction point itself is attached to the main RigidBody (box) through a fixedJoint, it starts to press it into other colliders, ignoring collisions, because the weight of the ControlPoint presses from above so strongly that it ignores the mass of the main object (box). However, I need to achieve an effect where pulling the attraction object would be difficult depending on its weight, and the lighter it is, the easier it is to pull it by moving the control point on the other end of the rope.
Code:
public void AttachRopeAtCurrentCenter(AttractionObject attractionObject)
{
_blueprint = ScriptableObject.CreateInstance<ObiRopeBlueprint>();
var fatherConnectionPoint = _playersContainer[PlayerCharacter.Father].ConnectionPoint;
var sonConnectionPoint = _playersContainer[PlayerCharacter.Son].ConnectionPoint;
Vector3 father = ObiRope.transform.InverseTransformPoint(fatherConnectionPoint.position);
Vector3 center = ObiRope.transform.InverseTransformPoint(attractionObject.AttractionPoint.position);
Vector3 son = ObiRope.transform.InverseTransformPoint(sonConnectionPoint.position);
int allLayers = (1 << 16) - 1;
int excludeLayer15 = ~(1 << 15);
int finalMask = allLayers & excludeLayer15;
int filter = ObiUtils.MakeFilter(finalMask,
1);
_blueprint.path.Clear();
_blueprint.path.AddControlPoint(father,
-father.normalized,
father.normalized,
Vector3.zero,
_controlPointsMass,
_controlPointsMass,
1,
filter,
Color.white,
"start");
_blueprint.path.AddControlPoint(center,
-center.normalized,
center.normalized,
Vector3.zero,
_controlPointsMass,
_controlPointsMass,
1,
filter,
Color.white,
"center");
_blueprint.path.AddControlPoint(son,
-son.normalized,
son.normalized,
Vector3.zero,
0.1f,
0.1f,
1,
filter,
Color.white,
"end");
_blueprint.path.FlushEvents();
_blueprint.Generate();
ObiRope.ropeBlueprint = _blueprint;
var pinConstraints = ObiRope.GetConstraintsByType(Oni.ConstraintType.Pin) as ObiConstraints<ObiPinConstraintsBatch>;
pinConstraints.Clear();
var batch = new ObiPinConstraintsBatch();
_centerOfRopePointCollider.transform.position = attractionObject.AttractionPoint.position;
if (attractionObject.Type == AttractionObject.AttractionPointType.Kinematic)
_centerOfRopePointObiRigidbody.kinematicForParticles = true;
batch.AddConstraint(ObiRope.solverIndices[0],
_fatherConnectionPointObiCollider,
Vector3.zero,
Quaternion.identity,
0,
0,
float.PositiveInfinity);
batch.AddConstraint(ObiRope.solverIndices[_blueprint.activeParticleCount - 1],
_sonConnectionPointObiCollider,
Vector3.zero,
Quaternion.identity,
0,
0,
float.PositiveInfinity);
var attachment = ObiRope.GetComponent<ObiParticleAttachment>();
attachment.particleGroup = ObiRope.ropeBlueprint.groups[1];
if (attractionObject.Type == AttractionObject.AttractionPointType.Kinematic)
{
attachment.target = attractionObject.transform;
attachment.attachmentType = ObiParticleAttachment.AttachmentType.Static;
}
else
{
attachment.target = attractionObject.AttractionPoint;
attachment.attachmentType = ObiParticleAttachment.AttachmentType.Dynamic;
}
batch.activeConstraintCount = 2;
pinConstraints.AddBatch(batch);
ObiRope.SetConstraintsDirty(Oni.ConstraintType.Pin);
}