Okay, so here’s what I have:
I’m developing for the iphone. I have a basic ship in the middle of a box (plane) There are three walls and one wall that consists of two pieces or doors. I have an animation to make these door’s slide open. However, I do not want them to slide open automatically.
I have a ship that is controlled by the accelerometer and locked to moving along only the x and z axis (to prevent the player from leaving the level from the top). I also have a script that shoots a missile from the right wing whenever the user taps the screen. This missile has a collider and explodes on collision.
What I want is the door to slide open when the missile collides with it. Can anyone help?
you should already have a collision box to your door, so the missile and player can collide.
what you would need is, if missile collides door, play open animation and set the collider to trigger. if its a trigger, a trigger event would take place, but can be ignored and all other objects can go through the trigger collider.
add a script something like this to your door (untested code ahead):
function OnCollisionEnter(collision : Collision) {
if (collision.gameObject.name=="missileName") {
animation.Play("Door@Open");
collider.isTrigger=true;
}
}
a better alternative would be, to build the door from two gameobjects with a box collider to each, and then move them apart when the missile hits, that way if the player would try to fly through the door while its half open, it would be more realistic, but its quite some overhead and therefore maybe its not worth it.