Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Obi rope, parenting and unity physics is not working
#2
(04-10-2017, 12:03 PM)Jusvalt Wrote: Hi all,

My deadline is so close and i am lost with this problem..

I use obi rope as safety rope in climbing VR (Vive) simulation. Other end of the rope is "pin constrainted" to the top of the cliff, other end is "pin constrainted" to the game object named carabine (obi collider) and that game object is child of the body of my player avatar (rigidbody with gravity and obi rigidbody). When I jump down from the cliff, obi rope is affect to my player's rigidbody and vise versa. Everything is working just as I excepted.

BUT!!

I need to attach the other end of the rope (carabine) (make it child of the player's body) AFTER the game start. And this causes issues. Obi rope is no longer affect to my player body rigidbody physics and rope stretch infinity until player is falling to the ground.

This is the problem:

I CAN use code and make game object (carabine) to child of the player's body only in awake function and everything is fine. But when I do this in start function or during gameplay, obi rope is not affect my player's rigidbody.

Yes, I can use fixedjoint on carabine and attach carabine to the players body instead parenting, but that's not what I want and it is not working right either. The joint breaks the connection so easily even if joint's breakforce is set to infinity. There is something that I cannot understand..

This is my game object hierarchy:

In start:
-Player body (rigid body with gravity, obi rigidbody)
-obi rope (pin constrainted to the "carabine" and other end to the "cliff hook")
-carabine
-cliff hook

when player attach the rope to his harness (parenting via code):

-Player body (rigid body with gravity, obi rigidbody)
 --carabine
-obi rope (pin constrainted to the "carabine" and other end to the "cliff hook")
-cliff hook

So why obi rope is not affected to it's parent's rigidbody when parenting the game object (which is pin constrainted to rope) during gameplay using a code but everything is working fine when it is allready child of the parent when the game starts or parenting it using code in awake function? This must be something like obi ropes initialize issue. How can I fix that?

And is this a bug or something?

So sorry of my English and messy explain, but I really need help to this problem as soon as possible.. So please..  Huh

The issue you're facing is that you're changing the root rigidbody of a hierarchy of objects at runtime. Obi will search for the root rigidbody of a hierarchy in the collider's Awake(), since traversing the entire hierarchy every frame is not a good idea.

So when the game starts, Obi finds that the carabine (or any other transform up its herarchy) has no Rigidbody attached, so it doesn't create a ObiRigidbody component to match it. If you reparent the object afterwards to a hierarchy that DOES have a rigidbody somewhere, Obi has no way to know that there's now a rigidbody further up the carabine's transform hierarchy.

Solution:
Go to ObiColliderBase.cs, and change the "CreateRigidbody()" method from protected to public.
Then in your code, after you reparent the carabine, call carabine.CreateRigidbody(). This will make Obi aware of the newly found rigidbody in the hierarchy.

Edit:
I wasn't aware of Unity's OnTransformParentChanged() event. You can just add:
Code:
private void OnTransformParentChanged(){
CreateRigidbody();
}
to ObiColliderBase.cs. By doing this you no longer need to manually call CreateRigidbody() each time you reparent the carabine.

cheers!
Reply


Messages In This Thread
RE: Obi rope, parenting and unity physics is not working - by josemendez - 04-10-2017, 12:31 PM