- Home /
How do I use joints to make floppy physics hair on a character?
What joints do I use to get basic floppy hair strands on a character controlled by the user?
I have a character with modeled hair strands in the mesh and bones with weight maps for the hair strands, and I would like physics of the user controlled movement of the character's head to make the hair strands flop about (dependent on momentum of the head of the character).
Preferably, I would also like some form of collision detection of the hair strand to the head, or instead constraints/limits on the amount the bones can rotate and rest at so the hair strand doesn't intersect with the head. These could be springy or floppy like a rag doll. I just want some secondary automatic motion to my character.
To this end instead of working with my complex rig, and since I can't find any good joint tutorials which are similar, I've created a test scene with a ball for a head and 2 scaled cubes for hair strands - all of them are connected using nulls/empty game objects so the pivots are in the right places, so that I can understand the mechanics of this in a clear fashion.
Given this scene above and assuming I have a script which lets me move the head/ball in any direction and position, what components do I add to which and which settings do I need to set to get this effect? I've played with this for awhile and can't seem to get anywhere.
I effectively only want gravity on the hair not on the character, because I am manually positioning the character in space with my controller script.
Thanks for any help :-)
Answer by Waz · Jul 05, 2011 at 06:59 AM
You should give SkinnedCloth a try for hair. It works very well and is quite easy to tweak for a satisfying result.
Thanks for your response. It's a complex character mesh with >4000polys and 22 bones, I tried that for the character's clothing and although performance was fine on fast machines - without self collision on - so the effect didn't look nice with the polys folding in on themselves and itersecting with the legs. I imagine hairstrands intersecting with the face would be far more obvious.
Your answer in the other post actually was the correct one. I'll repost here:
Arm
Hand
Anchor + Ribidbody with is$$anonymous$$inematic=true
Yoyo + Rigidbody + SpringJoint with connectedRigidbody=Anchor
The key is NOT parenting the Yoyo (thing that is floppy) to the character at all. The Connected Body property will do that.
It's actually a lot easier to tweak hair to not intersect a static head than clothes to avoid a pair of scissoring legs.
Answer by Chris D · Jun 15, 2011 at 05:22 PM
It's not really clear from what you've posted, but have you tried using a Hinge Joint?
It seems that you could achieve what you're after with one of these if you give it an appropriate Spring value.
I've tried all the joints. Sorry I'm not being clear, I'll try to elaborate more.
I have a skeleton rigged character with a couple of extra bones floating inside the character's hair strands (hair strands are kind of anime style). I have weight maps for them and if I manually rotate the bones in the unity editor they rotate the hair strands correctly. So in that example I have a bone called HairStrandLeft (which is parented to the Head bone). I am actually driving the character via a kinect but that is irrelevant. I want the HairStrandLeft to flop based on the momentum of the character's head.
In this picture in my test scene above I have a sphere for the head and boxes to simulate floppy hair strands. I've used Empty GameObjects (which I call NULLs) as parents to the sphere and boxes to allow me to change the "pivot points" of the meshes. i.e. the box's pivot point is its center, I want it to be the tip in this case so it can rotate on that tip and act like floppy hair.
So what do I do first? I assume something like this:
1) Add Rigid Body to my Head object, in this case NULL_Cube (sorry it is named badly in the screen shot, orginally I had a cube for the head)
2) Add a Hinge Joint to my Hair strand - in this case NULL_LeftStrand
3) Add colliders to each of those nulls that roughly match the shapes of their parented meshes? (I assume I might skip this step if I'm just using a continuous mesh with bones in the head and hair)??
4) Set some settings like Spring?
Steps 3 & 4 I am totally confused on. Plus as soon as I add a Rigidbody to the character(head in this case) it falls off screen despite being controlled by keyboard (for this test but kinect in my real app).
I've found that for the parent Head/Character object if I Freeze Rotation and Position (but not for the hairstrand) for all axis I can retain control of the main object without it falling to inifinty below. but then $$anonymous$$omentum of my controlled movements does not seem to be added to the hair joint - but it's clear I don't know what I should add where. I've tried ALOT of combinations and settings and can't get anything like the effect I am after.
I seem to have some ability in Unity, but clearly have a few big holes in my knowledge when it comes to physics. Thanks for your help figuring this out! :-)