Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Help  Replace pin constraint in runtime?
#1
I have a rope and at both ends there is a pin constraint to two different objects. After a 'event' i would like one of the pin constraints to be attached to a new object. How do i do this? i tried copying the code from the Grappling hook scene by doing this:

https://gyazo.com/df0ab0ef81ea4b37b709bb44f62ba535

Thanks in advance for any help!
Reply
#2
(09-04-2018, 12:53 PM)Karlanton Wrote: I have a rope and at both ends there is a pin constraint to two different objects. After a 'event' i would like one of the pin constraints to be attached to a new object. How do i do this? i tried copying the code from the Grappling hook scene by doing this:

https://gyazo.com/df0ab0ef81ea4b37b709bb44f62ba535

Thanks in advance for any help!

Hi there,

You can remove the old constraint, then add a new one that uses the new object just like you are doing. However you must pass the index of a constraint to RemoveConstraint(), not the index of a particle. (i.e. If you only have one pin constraint added, you should pass "0" as the index).
Reply
#3
(10-04-2018, 10:13 AM)josemendez Wrote: Hi there,

You can remove the old constraint, then add a new one that uses the new object just like you are doing. However you must pass the index of a constraint to RemoveConstraint(), not the index of a particle. (i.e. If you only have one pin constraint added, you should pass "0" as the index).

https://gyazo.com/e25e93e5929bdff59c0c5ba40936fc40

Did this now. The pin constraint does get removed but the rope is still attached to the first object that had the pin constraint from the beginning and no new pin constraints were added to the last particle. I was not sure what to pass in the rope.addsolver(?) so i tried both with null and the pinconstraint. Where am i doing it wrong haha?
Reply
#4
https://gyazo.com/1209171286ff574f67ac3cecb6e3a6f9


With this code the pin constraint gets removed from the seleted particle in the "edit particle" tab.

However, the rope is still attached to the gameobject. why is that?


[quote pid='1571' dateline='1523449457']
i also found this:
http://obi.virtualmethodstudio.com/forum...d-229.html

They seem to have the same issue as i do.
[/quote]
Reply
#5
(11-04-2018, 01:24 PM)Karlanton Wrote: https://gyazo.com/1209171286ff574f67ac3cecb6e3a6f9


With this code the pin constraint gets removed from the seleted particle in the "edit particle" tab.

However, the rope is still attached to the gameobject. why is that?


[quote pid='1571' dateline='1523449457']
i also found this:
http://obi.virtualmethodstudio.com/forum...d-229.html

They seem to have the same issue as i do.

[/quote]

You must remove the constraints component (constraints.RemoveFromSolver(null)) from the solver and re-add them (constraints.AddToSolver(null)) after. If you just remove, add or modify constraints while they're in the solver, the changes won't be pushed to the solver. Please read the docs:
http://obi.virtualmethodstudio.com/tutor...aints.html
Reply