- Home /
How Does a Ragdoll Grab onto other objects?
Hi everyone. I am currently making a 2d game with 3d graphics. I am trying to make the main character (ragdoll) grab onto a cube or any other object which can then release himself with the hit of a button. He could then either bounce off of objects or grab onto other objects.
I am fairly new to unity and so had some trouble coming up with the best method to use this, should I use a hinge joint? and also if you can provide some code examples (C#) I would greatly appreciate it.
Thanks
Answer by Owen-Reynolds · Aug 03, 2011 at 01:12 PM
Off the top of my head:
o Each rigidbody gets one joint (which makes sense, since a door with a hinge on two edges can't open.) If you want to swing from the hand, the arm/hand joint will be "used up" connecting itself to the shoulder. You could try childing an empty isKinematic rigidbody (only RBs can have joints, see below for kinematic) to the hand, and giving that a joint for the "grab."
o If you use the hand, code will be something like: grabber = tranform.find("bones").find("shoulder").find( ...
and then grabber.GetComponent("hinge").connectedBody = otherRB
.
o Joints can only grab onto other rigidbodies, which means "things physics is also moving around." If you try to connect to a solid cube (do it in the Inspector, first, just to get a feel,) you'll get yelled at for not having an RB. The trick is to give all of your "grab onto" objects an RB and set it to isKinematic (that setting is specifically for this special case of a frozen physics object.)
o All joints are interchangable. If you want the person to always swing forwards/backwards, then use a hinge joint and set the axis of swing. If you want them to be able to also swing sideways, use a character joint (it works more like a ball-socket.)
o It might be easier and look as good to just have the main parent object have an invisible 3 foot RB/collider child (like aiming an invisible telekenetic arm.) To grab something, have that do a LookAt to what you are grabbing and hook up the joint end.
Your answer
Follow this Question
Related Questions
Multiple Cars not working 1 Answer
Distribute terrain in zones 3 Answers
Best practice for adding specific attributes to an object but not all of them 2 Answers
Grabing and moving a box(C#) 3 Answers
Objects Stuff 1 Answer