- Home /
Use low-poly collision mesh for a high-poly model?
So I have a high-poly zombie model (from Mixamo) - I'm working on a body-sensitive damage system where if you hit the head you cause more damage, hit the feet the zombie might fall, etc. So obviously I need good collision detection for this. Using primitive colliders foreach part is just too tedious... Using a MeshCollider is very expensive. So I told my modeler to create a low-poly/decimated mesh to use for collision.
But here's the problem:
I have no idea how to align the low-poly mesh with the model... i.e. how to make the model 'wear?' his collision mesh? not to mention the character's animated so he's gonna be moving at runtime so the collision mesh should update too... (Note that the zombie's using a SkinnedMeshRenderer
...)
I'm just looking for ideas here/kickstarts...
Thanks for any help!
I may be wrong but I think collision meshes don't animate so if you use a separate collision mesh your collisions wouldn't be in the correct place.
I'd also suggest using composite colliders as per @zharik86 answer. That's what I did for the goalkeeper for my soccer game.
Thanks for dropping by. You are correct. There's a thread in the forums that updates the mesh but it's pretty damn expensive... I ended up going for composite/compound colliders like you saw in my other collision issue video...
Yes but I actually added position handles to them so I could easily position them ins$$anonymous$$d of having to manually input coordinate values which is pain. Combine that with orthographic view, and it's a bit more acceptable... $$anonymous$$aybe later on as things become clearer I could figure out a way to automate the process.
Answer by zharik86 · Aug 16, 2014 at 06:31 AM
Certainly, in my opinion, the best decision is composite colliders with unique tags: head, foot, etc. It is interesting how define you in what section of a body hit when using meshCollider? Probably only on coordinates. On your picture at you objects don't match. Check pivot point at your two models. For check simply move two your fbx on a scene to coordinates (0,0,0) and look at result. Also it is possible to check in any 3d editor. For example, in the 3D Max. Most likely at high-poly pivot to be below under feet, and in low-poly - in the middle of model.
Hi thanks for your answer!
It is interesting how define you in what section of a body hit when using meshCollider?
The thing is, I'm using Final I$$anonymous$$. It has a Hit Reaction demo which is nice. From the HitReaction
script, you create hits and reference the body parts that you would like (head, arm, leg, etc) So what I did (my initial attempt) is, when the player's shoot a zombie (via raycast) I get the nearest body part to the raycast hit.point, and then apply damage to that body part... It worked pretty well. It even works (in a not-so-great way) if I just used a capsule collider for the whole zombie...
It might well be a coordinate issue yes... but even if I solve it, I still need to have the collision mesh be adjusted when the character's animating...
I agree with @zharik86 - if you break apart your low-poly model into separate submeshes (for upper arm, lower arm, hand etc.) then you can parent them to the corresponding bone in the high-poly model's armature and they will stay aligned when the model is animated.
I can't see how you'd do this otherwise, short of duplicating the armature, controller, and all animations across both models.
@vexe When at you it will turn out to combine correctly models then it is necessary to make their animation. @tanoshimi is right, objects duplicating is necessary. For example, I did game in which on the hero it was necessary to dress the armor (a helmet, a torso, gloves, etc.). Naturally, all armor and the hero are made on one rig. But I separated finite files: separately fbx of the hero, separately fbx of a set of armors. Now main thing for object with animation: if you open it in the Inspector, has the main mesh (the hero, the zombie or something else) and a tree of simple gameObjects with the Transform component (in fact a tree of bones). Skinned$$anonymous$$eshRenderer is bound to this tree. Any animation changes tree components, and we receive a certain movement of parts of a body of the hero. If to create gameObject with the Skinned$$anonymous$$eshRenderer component and to make binding programmatically on the same bones, as at the main hero, created gameObject also will be animated (provided that rig are identical).
So, you have two models. First (high) has an animation, at second (low) the binding to identical rig shall be made in the 3D editor. Then they can be combined programmatically and further to make prefab. There is the second way (easier), two models shall be in one fbx file.
Sorry if I sound thick-headed (which I am, I have no experience with animation nor modeling techniques, I'm purely a programmer), but I don't know what you mean guy by 'object duplication' - $$anonymous$$aybe I should have mentioned that my zombie model (the high-poly) is actually split into different transforms (spine, chest, body, leg, shoulder, thigh, hips, etc). So you're saying the best way to attach colliders to these body parts?
You dont use low poly colliders for skinned mesh objects. Atleast from what I know and understand it is never done this way.
I know you are against the primitive colliders...but its the best way I have found for hit detection. Attach primitive capsule colliders to the actual bones. Bones are just points in space just like any other game object.
$$anonymous$$ake a new game object, child it to a specific bone (try the head first). zero it out. add a sphere/capsule collider component. scale it correctly so it fits just outside the mesh of your character. $$anonymous$$ark as trigger.
I put my hit detection objects on their own layer
$$anonymous$$ake sure in the physics matrix that the hit detect colliders do not collide with themselves or the enemy it is on. Attach a simple script with some bools on it..
public bool head;
public bool leftArm;
public bool rightArm;
public bool leftLeg;
public bool rightLeg;
$$anonymous$$anually check each collider youve made with the correct bool.
Whatever hits these objects (if its a ray make sure you layermask the hitdetect layer) do a check.
if(hit.collider.getComponent<YourHitDetectScript>().head){
ExplodeHead();
}
This really isnt a tedious process. Once its set up its done. You could even set up one collider and copy/paste it to the other bones. Zero out the position/rotation. Fix the scale of it. select the correct bool for your hit detect script. Done
Your answer
Follow this Question
Related Questions
Find right mesh for collider 1 Answer
Scale collider independent of gameObject. 1 Answer
Correct position of overlapping meshes 0 Answers