- Home /
Dragging and rotating a Rigidbody2D (Limbs with HingeJoint). Shadow Play / Puppetry Simulation
I'm trying to make a program in Unity for playing around with shadow play puppets (mostly "Karagöz"). The characters i want to use made out of jointed limbs. There is a hole on their upperbody which allows to use sticks to move them behind curtain and rotate the bodies: Example1
I build the 2D characters with HingeJoints to simulate how they actually move. i think best way to move them is using mouse. You can drag them with mouse and use the scroll wheel to rotate the bodies. I put a circle collider on the hole of the character and used a similar script like this one to drag my character. My problem is the dragRigidbody2D solutions based on using a spring joint, and its just too springy for my usage and doesnt allow me to use rotating from the same point. I think its same for the TargetJoint2D. I made a little test and it looks way too springy too.
Has anyone an idea how to achive dragging and rotating 2D Rigidbodies with Hingejoints from this certain hole without making it springy / bouncey?
Are your "puppets" set upcorrectly as far as hierarchy? By that i mean, the hand is a child of the arm, which is a child of the shoulder, which is a child of the chest, etc? The top most parent should be the "root". If you are unfamiliar with rigging a model, check out any 3d model that is provided for free on the asset store (unity kyle) and look at the bone hierarchy. I understand you are working in 2d space, but the concept is the same. This way, when you move a parent joint, the children joints inherit the parent properties and adjust themselves in local space accordingly.
Yes, they are correctly set up. Two legs attached to hip and hip attached to upper body. Legs are children of the hip and hip is children of the upper body. $$anonymous$$iddle point of the upperbody is placed on the hole to move them from that point. It helped me to add the target/spring joint exactly at that hole. $$anonymous$$y question is: how can I move/drag the body staticly, not bouncy as if they are hold by an elastic string. There must be way, which allows to move the puppet as if I hold them with the sticks like in the picture above staticly and rotate them like the rolling the sticks back and fort.
is there any way you can show me what you mean? With joints I am assu$$anonymous$$g you want the classic "puppet" effect where the limbs are dangling and swinging around. Do you mean the joints become "disconnected" and pop back into place? Or do you mean they rotate freely?
@b1gry4n @ianjgrant here we go:
an example about how it should move
an another example with challenging movements
The project is here: github-link additionally i added a video about what i meant.
i think its quite important to specify what i asked. you can see i used a spring joint, and i would like to drag the puppets without spring effect, without bouncing around. so:
Q1: is there a way for dragging such rigidbodies without usage of a spring joint? (for static movements)
Q2: if i have to use a joint to drag them, then how can i implement target joint with a script so that i can move "target" with mouse? (basically, how can i implement targetjoint?)
Q3: how can i rotate the body back and fort with mousewheel -while i drag it with mouse simultaneously- ?
thank you all very much!
While the movements you are after might seem simple, its actually kind of complex. I notice that the feet are planted with knees bending, backs bending, heads and arms are loosely connecting. This all re$$anonymous$$ds me of inverse kinematics. Something you want isnt exactly rotating the joints themselves, but having control nodes that represent parts of the body. It is standard practice in 3D animation to create a rig for the 3D model. Check out this video to understand what I am talking about. https://youtu.be/uQFzqI3WO7I?t=35s
The reason is, its tedious and more difficult to select and rotate joints/bones, so a controller is made. I think this is something you would want to do as well. If you look at it, the idea is super similar. 3D animation is a lot like recording a puppet moving. Like I said before, I understand youre ai$$anonymous$$g for 2D, but the idea behind what you want is extremely similar to what I just mentioned.
Take a look at these unity assets. They might give you some ideas.
https://www.assetstore.unity3d.com/en/#!/content/48977. https://www.assetstore.unity3d.com/en/#!/content/14290
And, unity does have inverse kinematics (I$$anonymous$$), but as a pro only feature : https://docs.unity3d.com/$$anonymous$$anual/Inverse$$anonymous$$inematics.html
Again, I realize this is aimed at 3d, but you can for sure use it in 2D space if set up properly. This is the type of stuff you will want to implement and use in your project. So what you would do is have the controllers, or effectors, be the things you are moving/controlling and they influence the joints/bones associated.
do you think so. actually its kinda simple how the puppets built. every limb attached to another with simple strings like a chain and they move like hinge joint without limitation. the moves wich you see are just talent of the puppet artist making simple puppets looks so strong on expression. At this state i ignore the secondary control instances like that one arm. i hope to move it later with keybord (direction buttons).
believe me or not, what you see is just good artistic use of this stick i explained already. he rotates and "drags" the puppet and illusion is there.
Answer by ianjgrant · Oct 13, 2016 at 11:19 PM
HI,
I have a lot of experience solving this problem with my performance animation / multitouch 'ShadowEngine' part-time PhD project. I collected 200+ images of Karagöz figures from European museums to use in the system.
The script you reference sets up a generic 'dragging' spring joint with default settings that pulls the hit rigidbody around.
Plenty of designs / approaches will achieve what you are after. My latest attempt experiments with how many touch controls are useable (in a HCI sense - mine is a multitouch context not just mouse control. Interestingly, mouse control is sometimes more effective / expressive thank multitouch when operated live). In the image below - each coloured drag zone is a 'fixed' hotspot and has different 'spring' settings attached to the local rigidbodies. Some controls are parented to another that when it rotates you get a 'marionette' controller effect which is very nice. Double click = rotate puppet to face the other direction (I tween the x scale). When using an iPad - this object rotates nicely around anchored finger points (in the XY plane). An effect I've been looking for for ages.
One thing worth trying: a distance joint is a spring joint with the freq.= 0 and damp. ratio = 1 (I think). Play with those settings in the controlling spring object. I've thought it a good idea to expose the spring settings to edit them at runtime to get the right balance for each puppet. See the following thread - where I'm trying to create a generic UI for this: unity answers thread
You do have to iterate a lot with settings for the joints and rigidbody properties. e.g. Rigidbody: The mass of each object in the hierarchy matters as do the drag values.
It is easy to freak out the physics in these set ups. So finding 'balance' in the system is a careful act of tweaking settings...
I hope this helps. Do PM me as I'm interested in every digital puppety project I find.
Question: what 'body' do you rotate with the mouse?
Kind regards, Ian
Hi, Thank you very much for your answer. I actually read and watch everything you made :) and I wanted to contact you after I have something to share.