Animating meshcollider with mesh animation

Hi,

I’m having a mesh that has one looped animation and it seems that when I add a MeshCollider to it, the MeshCollider keeps its original position/form…the MeshCollider isn’t animated.

How can I make my MeshCollider follow the animated mesh vertices ?

I use physics, so I can’t easily use the IsTrigger flag, 'cause it’ll make me write too much code I think…

Thanks

You can’t, but even if you could, it would likely be very slow. Mesh colliders take a lot of heavy preprocessing to make, so it’s not practical to update them every frame. Instead you can make a few primitive colliders for the general shapes you need and have them follow a few bones.

–Eric

Thank you Eric

the problem is that my animated mesh makes large moves, so it make things really wierd when my character collides with ‘nothing’ instead of the real mesh… :frowning:

I dont know very much about the use of bones in Unity…Globally, how can I make some colliders follow the bones ?

Otherwise, is the ‘trigger’ solution available ? In fact, there’s something I didn’t understand : when I import the FBX, in the settings, I can specify ‘Meshes have colliders’, but it don’t understand what it means, as I always manually added MeshColliders on my objects. What does this option stands for, please ?

:?:

Bones are just game objects, and can be treated the same as any other; i.e. they have transforms and so on.

Not really sure what you mean…rigidbodies with “isTrigger” on don’t behave any differently, aside from being triggers of course.

It just adds a mesh collider for you.

–Eric

This answers a problem i also had, with an animated door.

I tried adding all types of collision, but when the door opened, the player still couldnt go through the door, then i realised the collision wasnt moving with it.

Am i right in saying that what i need to do is add a collision mesh that animates with the door, then use that as the collision mesh? Surely thats just the same principle of adding a box collider, except the box collider wont animate

Thanks

Steve

OK, thanks, I’ll try with adding colliders on bones.

Bye

Well, a door would be very easily served by a box collider. Generally you don’t want to use mesh colliders for anything that moves, if you can get away with it (or any objects at all, actually, if they can be approximated with primitive colliders). As discussed above, mesh colliders don’t animate. Personally I make doors with code rather than using animations (much more flexibility that way), but if you did animate a door, then attach a box collider to the bone for the door and make the collider have the appropriate dimensions so it matches up.

–Eric

Hi

I added the box collider, but it does not move with the door. WHen the door opens, the player cannot move through the space.

Thanks

Steve

I have uploaded the door object if you could be so kind as to check it out. You will also see that my door animation doesnt finish to its last keyframe, and doesnt close as it should(i imentioned this in another thread)

http://www.arteria-gaming.net/door.rar

Thanks

Steve

This is the code attached to the fps camera.

var dooOpened:boolean = false;
var doorAudio : AudioClip;
var doorShut:AudioClip;
var timer:float = 0.0;

function onControllerColliderHit(hit:ControllerColliderHit){
if ((hit.gameObject.tag==“house1door”) (doorOPened==false))
{ openDoor();}

}

function Update()
{
if(doorOpened)
{timer+=Time.deltaTime;}

if(timer>=5)
{shutDoor()};

}

function shutDoor()
{
var theHouse=gameObject.FindWithTag(“house1door”);
theHouse.animation.PLay(“closedoor”);
doorOPened=false;
timer = 0;
}

function openDoor()
{
doorOPened = true;
var theHouse = gameObject.FindWithTag(“house1door”);
theHouse.animation.PLay(“opendoor”);

}

The player has the tag “house1door”

Steve

Attach the box collider to the correct bone, and make sure it’s sized and positioned so that it matches the door.

–Eric

Interesting… i assigned the door collision mesh to the door mesh, but you see i need to attach box collider to the bone that animates the door?

STeve

HI

I tried it and it doesnt work, as the main door is named as the tag, and the bone is part of its mesh, unity is not seeing the bone as having the animation but obviously the main door item, therefore when the player aproaches the door, the collision works, but now the door doesnt open.

I raelly didnt know it was this hard for animated collision objects.

Thanks

Steve

I’m not sure what you mean…the bone that’s animated is called “Bone”, and is below U3DRoot and above Bone1. It works fine, although the door file could be simplified a lot–the animated bone is buried under a number of transforms which don’t need to be there.

–Eric

Is there any way to do this kind of parenting to bones in Blender instead of in Unity? I’m creating all of my colliders in Blender, as meshes, and having them automatically converted to colliders. Blender doesn’t seem to allow me to parent to bones, only to the whole Armature.