x


On Collide Destroy Game Object

Hi. this is a simple question. but id like a script that made it so when a collided with a certan game object it will delete it from the level.

Thanks!!! Post a script.

more ▼

asked May 07, 2010 at 05:49 PM

Colin Allen gravatar image

Colin Allen
116 15 14 15

There are a lot of questions that answer this question. For example, from the search results just of what you put in the title: http://answers.unity3d.com/search?q=On+Collide+Destroy+Game+Object+, you get to this thread: http://answers.unity3d.com/questions/4145/how-to-make-objects-collide-and-something-happen which asks and has answered this exact question.

May 07, 2010 at 10:18 PM Tetrad
(comments are locked)
10|3000 characters needed characters left

2 answers: sort voted first
var certainGameObjectName : String = "Bob";

function OnCollisionStart(collision : Collision)
{
    if (collision.gameObject.name == certainGameObjectName)
    {
        Destroy(collision.gameObject); // destroys the thing this script bumped into
    }

}
more ▼

answered May 07, 2010 at 06:04 PM

Mike 3 gravatar image

Mike 3
32.8k 18 80 290

(comments are locked)
10|3000 characters needed characters left
var explosionPrefab : Transform;

function OnCollisionEnter(collision : Collision) { // Rotate the object so that the y-axis faces along the normal of the surface var contact : ContactPoint = collision.contacts[0]; var rot : Quaternion = Quaternion.FromToRotation(Vector3.up, contact.normal); var pos : Vector3 = contact.point; Instantiate(explosionPrefab, pos, rot); // Destroy the projectile Destroy (gameObject); } function Update () { }

then put your explosion prefab in, (save the script then click and drag your explosion onto the empty slot) if you do not have an explosion prefab you can download 1 free of the unity website, link below :)

http://unity3d.com/support/resources/unity-extensions/explosion-framework

this is great, it gives you loads of explosion prefabs (if u want 2 publish i think they have copyright though, not sure look into it)

more ▼

answered Nov 27, 2010 at 10:36 PM

oinkoinkflapflap gravatar image

oinkoinkflapflap
242 155 538 143

i dont know how 2 do the fancy script thing, you may have to rearange that on different lines and stuff, or not, im not sure, sorry :P

Nov 27, 2010 at 10:38 PM oinkoinkflapflap
(comments are locked)
10|3000 characters needed characters left
Your answer
toggle preview:

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Topics:

x3374
x1168
x1010
x194
x95

asked: May 07, 2010 at 05:49 PM

Seen: 34040 times

Last Updated: May 07, 2010 at 05:49 PM