Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Help  Moving Pin Constraints?
#1
I'm wondering is it possible to move pin constraints around on their attached collider's local space.

I have the following code (adapted from one of your samples),


Code:
ObiConstraints<ObiPinConstraintsBatch> pinConstraints = m_ropeBlueprint.GetConstraintsByType(Oni.ConstraintType.Pin) as ObiConstraints<ObiPinConstraintsBatch>;
ObiPinConstraintsBatch batch = pinConstraints.batches[0];
        
batch.AddConstraint(0, m_parentCollider, m_parentCollider.transform.InverseTransformPoint(SourcePosition), Quaternion.identity);
batch.AddConstraint(m_ropeBlueprint.activeParticleCount - 1, hitCollider.GetComponent<ObiColliderBase>(),
                                                    hitCollider.transform.InverseTransformPoint(hitPosition), Quaternion.identity);

batch.activeConstraintCount = 2;

I want to later come back here and say 'move constraint 0'. The "SourcePosition" property here will always provide the correct desired position in world space.

I thought maybe I could do something like this, but nothing seems to happen when I call it:


Code:
private void SetStartConstraint()
{
    ObiConstraints<ObiPinConstraintsBatch> pinConstraints = m_ropeBlueprint.GetConstraintsByType(Oni.ConstraintType.Pin) as ObiConstraints<ObiPinConstraintsBatch>;
    ObiPinConstraintsBatch batch = pinConstraints.batches[0];

    batch.offsets.SetVector3(0, m_parentCollider.transform.InverseTransformPoint(SourcePosition));

    //batch.AddConstraint(0, m_collider, m_parentCollider.transform.InverseTransformPoint(SourcePosition), Quaternion.identity);
}

Any ideas? Or maybe this is inadvisable?
Reply
#2
Hi there!

You're getting the constraints from the blueprint, not the actor, at runtime. Blueprints are assets, and they work just like prefabs: once you instantiate a blueprint, the instances (actors) are no longer "tied" to it. So changing a blueprint at runtime will only affect all instances created from that point on, existing instances will be unaffected. See:
http://obi.virtualmethodstudio.com/tutor...cture.html

Step #2 of what happens when an actor is added to the solver is key here:
Quote:The actor makes a copy of all constraints found in the blueprint, and updates their particle references so that they point to the correct solver array positions.

So do the same, but this time get the constraints from the actor instead (rope.GetConstraintsByType()).
Reply