Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Help  Add constraint following hook example
#1
I'm following the RopeGrapplingHook example in order to achieve a similar example but with already created ropes. So my idea is that when I press a certain button a constraint is created between the rope and the player:
Code:
    public ObiRopeBlueprint m_ActualBlueprint;
    public ObiCollider m_Player;
    public ObiRope m_Rope;

    void Update()
    {
        if (Input.GetKeyDown(KeyCode.K))
        {
            AddConstraint();
        }
    }

    void AddConstraint()
    {
        var pinConstraints = m_ActualBlueprint.GetConstraintsByType(Oni.ConstraintType.Pin) as ObiConstraints<ObiPinConstraintsBatch>;
        var batch = pinConstraints.batches[0];
        batch.AddConstraint(0, m_Player, transform.localPosition, Quaternion.identity);
    }

But when I press the button I get the following error:
NullReferenceException: Object reference not set to an instance of an object
Obi.ObiPinConstraintsBatch.AddConstraint (System.Int32 index, Obi.ObiColliderBase body, UnityEngine.Vector3 offset, UnityEngine.Quaternion restDarboux) (at Assets/10-Vendors/Obi/Obi/Scripts/Common/Blueprints/Constraints/Batches/ObiPinConstraintsBatch.cs:82)
LianasTest.AddConstraint () (at Assets/10-Vendors/Obi/Obi/Scripts/RopeAndRod/Utils/Temporal/LianasTest.cs:26)
LianasTest.Update () (at Assets/10-Vendors/Obi/Obi/Scripts/RopeAndRod/Utils/Temporal/LianasTest.cs:17)


I assume that I'm doing something wrong, I have checked the batch var and it's not null so I'm not really sure what is the problem with AddConstraint.
PS: I made the following modification:
Code:
//var pinConstraints = m_ActualBluePrint.GetConstraintsByType(Oni.ConstraintType.Pin) as ObiConstraints<ObiPinConstraintsBatch>
var pinConstraints = m_Rope.GetConstraintsByType(Oni.ConstraintType.Pin) as ObiConstraints<ObiPinConstraintsBatch>

I read that blueprint acts as a prefab so in runtime cant be modified. Now I'm not getting any error but the constraint isn't happening anyway.

Regards!
Reply


Messages In This Thread
Add constraint following hook example - by flaurens - 20-10-2020, 02:09 PM