- Home /
play animation when thrown object collides
new to unity and terrible at javascript. trying to do some basic stuff with triggering an objects animation when it collides with a box I'm throwing. I've tagged my stuff, done everything proper, but can't get script to do what i need. here is the script:
var speed = 3.0;
var boxy:Transform;
var doorOpened : boolean = false;
var other : Animation ;
function Update() {
if(Input.GetButtonDown("Fire1"))
{
var crate = Instantiate (boxy, transform.position, Quaternion.identity);
crate.rigidbody.AddForce(transform.forward * 2000);
}
}
function OnControllerColliderHit(hit:ControllerColliderHit) {
if((hit.gameObject.tag == "ballboy") && !doorOpened)
(hit.gameObject.tag =="boxy");
}
function openDoor(drill : GameObject) {
doorOpened = true;
drill.animation.Play("spin");
}
I've grabbed some random code i found, so the variables won't make sense. i want to cause a sphere floating in space to kick back (kick back is the animation) when my "boxy" (box thrown) hits it. help greatly appreciated.
Answer by DaveA · Mar 20, 2012 at 10:19 PM
Take this out:
function OnControllerColliderHit(hit:ControllerColliderHit) {
if((hit.gameObject.tag == "ballboy") && !doorOpened)
(hit.gameObject.tag =="boxy");
}
You want a script on the object-getting-hit, OnCollisionEnter (see http://unity3d.com/support/documentation/ScriptReference/Collider.OnCollisionEnter.html) that will start the animation on that object.
Thanks. Please hit the checkbox next to my answer so we know it's 'done'
actually now I've run into a problem with something additional I'm trying to do. I've downloaded a bunch of "explosion" prefabs and I'm trying to trigger them on collision. I'm not sure how i should make these animations, or what i should do
Ok, so that's a NEW question, you should start a whole new question. And you should check the checkmark next to my answer.