- Home /
UMA Calculate Head Collider at Runtime
Hi guys,
i'm woundering how i could calculate the head collider for a UMA Char at Runtime.
A Capsule collider for the whole avatar is easy done but is there an way to seperate the body height and the head ?
THanks in advice!
hello, i have never used uma but maybe i can help you. why are you havinig issues getting the head collider?, what do you mean by calculate, get the radious? it is a mesh collider? can you share a screen shot of the collider from the inspector?
Answer by DCordoba · Feb 05, 2019 at 10:18 PM
you can attach a collider to each part of te body and check separate damage on the parent body script when a collider send the OnCollisionEnter to the MonoBehaviours also sent it to all the parent's MonoBehaviours on hierachy, so from a common parent you can manage the the collisions on all their children, by example on the UMA parent, you can manage all the collision to the child parts:
void OnCollisionEnter(Collision collision)
{
foreach (ContactPoint contact in collision.contacts)
{
if(contact.thisCollider.CompareTag("head")){
//add damage to head here
splashBlood (contact.point);
}
if(contact.thisCollider.CompareTag("torso")){
//add damage to torso here
splashBlood (contact.point);
}
if(contact.thisCollider.CompareTag("limb")){
//add damage to limbs of body here
splashBlood (contact.point);
}
}
}
if you cant attach a child with a collider (by example a tank with a weak point without external/child mobile parts) you can determine the position of he "weak point" by math: lets supposed that the weak point is 1.5 units above the center and have a radius of 0.3 (like the head is above of torso, or a turret above the tank...)
void OnCollisionEnter(Collision collision)
{
foreach (ContactPoint contact in collision.contacts)
{
if(contact.thisCollider.CompareTag("Tank")){
//calculate the headpos in global space
Vector3 headPos = transform.position + transform.up*1.5f;
//check if the contact was close to the weak point (inside the weak area)
if((contact.point - headpos).sqrMagnitude < 0.3*0.3){
//add damage to head here
}else{
//add damage to the rest of the tank here
}
addDecal (contact.point);
}
}
}
Hi,
thanks for your answer, but thats not that what i need, i need to create the colliders at runtime at the U$$anonymous$$A Character-
U$$anonymous$$A is creating one complete $$anonymous$$esh, its not seperated in head and body thats why its get tricky.
you can use the AddComponent to add a sphere collider at the head position, that doesnt work?
Would work, but how to get the head position?
yep, a single mesh, but the old U$$anonymous$$A had a child gameObject for each bone modifier of the mesh, who can be modified attaching a collider to each one, that was modified? sorry I dont use that since a year
ahh you mean i should create them on the bones?
https://gyazo.com/82767a06741abe482e3ee9312ea7ab63
I'm working at a online U$$anonymous$$A integration, i have to put many scripts at the main U$$anonymous$$A char (liek char controller, health, etc pp) and i render the bones in the editor cause i have to put some scripts before the main object get active, otherwise i dont get them right in sync.
is there an way to recalculate the bones at runtime? so dont delete and add them again, just set the correct size and posision?
Your answer
Follow this Question
Related Questions
MeshCollider invert 0 Answers
Distribute terrain in zones 3 Answers
Multiple Cars not working 1 Answer
Can't get a laser working properly. 2 Answers