- Home /
The question is answered, right answer was accepted
Adding collider to 3D model
I made small project which used models made in blender.
Shooting targets (I mean those red-white circles) have animation of hiding and showing.
I want them to have collisions (only circles, without base). Of course collisions don't follow bone animations.
What the easiest way to make collisions that follow those shoting targets? As far as I found only way is to make collider on bone, but that is kind of irritating, and there should be better ways which I don't found by myself.
$$anonymous$$ake the colliders seperate GameObjects and make them children of the bones.
("Children of the bones"... that could be the name of a Death $$anonymous$$etal band!)
@Cherno // That's the way I made it now because of the offset a needed to add, but this seems little clunky.
There are no other was. Only a Skinned$$anonymous$$eshRenderer mesh deforms with bones, colliders always stay rigid.
(This is just speculation, but) Physics collisions with complicated geometry can be very costly to performance, which is why simple primitive colliders (which have been optimised) have been provided. $$anonymous$$eshCollider is the more general solution for making other collider shapes. However, convex $$anonymous$$eshColliders can only have a small number of triangles because of how performance costly the algorithms can get. Creating a full mesh rigging system would be even more so.
Does your mesh really have to be skinned? They look like rigid blocks to me.
Answer by Tom507 · Feb 16, 2018 at 12:08 AM
Try this script for calculating the points for each zone when you have a working collider, yes i was bored XD.
public int pointsForHit (GameObject targetMiddle, Collision col)
{
Vector3 relativePosition = col.transform.position - targetMiddle.transform.position;
{
if (relativePosition.magnitude < 0.2f/*this is the outer radius of your bullseye / middlezone */) {return 100; // these are the points the player gets they are returned by the function
} else { if (relativePosition.magnitude < 0.4f /*this is the outer radius of your zone 1 */) { return 50; // points for hit on zone 1
} else { if (relativePosition.magnitude < 0.6f) { return 40;//points for hit on zone 2
} else { if (relativePosition.magnitude < 0.8f) { return 30;
} else { if (relativePosition.magnitude < 1f) { return 20;
}}}}}}
}
/*usage :*/ int anyVariableOfYourChoosing = pointsForHit (emptyGameObjectAtMiddlepoint, yourCollision)
I don't tested it yet, but that looks like it would work and in my opinion deserves a vote.
That approach works, but I think better would be to create more colliders, one for each ring.
it would also be less performant and not guaranteed to produce persistend results, unitys collider systhem doesn't behave consistendly at high velocitys - it detects sometimes earlyer sometimes later, if you have a shot com$$anonymous$$g in from an angle and it is detected too late it might be in another collider. I forgot in my script to take care of that offset, I'm correcting it.
Answer by calpolican · Feb 16, 2018 at 01:51 AM
Colliders can't follow bones? Sure they can! Place an empty game object as a child of the bone and give the empty game object a collider component in the inspector. That's surley the best solution, and I'm positive it works as I have use it many times. Just be sure not to confuse the bone with the effector ;)
When I said that colliders can't follow bones I mean that they don't deform like rendered mesh. But of course I can parent it to bone.
Ehmmm... judging by the image you provided, your mesh is not defor$$anonymous$$g at all. Do the targets have soft weights painted in their rig? They look like rigidbodies to me. Just put a collider to all the targets and that's that.
Thing is that they aren't defor$$anonymous$$g by soft weights, but they're using bones to animation.