#Projectiles is not dissapearing

1 messages · Page 1 of 1 (latest)

paper osprey
#

or when it touch the ground it dissapears

#

cos rn it just rolling around

night burrow
#

Google how to detect collisions in Unity.

harsh oyster
#

Just add Destroy(gameobject) in the function responsible for the collision with the wall or with someone

paper osprey
#

so i need to write this for ever ssingle 3d object and etity?

night burrow
#

No.
You need to write one single script that reacts to collisions and destroys the object it is attached to.
Then you attach that script to your projectiles.

harsh oyster
#

Or add this code in the script that is attach to the projectile, in the script now eeh, add the code lastly in the function (OnTriggerEnter or OnCollisionEnter) that is responsible for the collision with the walls or ennemies

paper osprey
#

do i add the script into the "projectile model" or the enemy

#

i made a script looking like this

#

private void OnCollisionEnter(Collision collision);
{
Destroy(collision.gameObject);
}

#

which gameobject do i add the script to

night burrow
#

Do yourself a favour and think about this for a moment.

collision is the object that was collided with (ergo not the object that the script is attached to).

Taking it a step further, this means that whatever object you attach the script to, will indiscriminatorily destroy everything it collides with.
I do not think that this is what you want, necessarily.

paper osprey
#

yea

#

cos when i use this script and put it in the projectile which is a 3d model

#

it destroyed everything

#

wait im braindead

harsh oyster
#

If you want to destroy the projectile when it touches something, then in the script that is attach to the projectile model simply type Destroy(gameObject) in the OnCollisionEnter function

indigo ember
#

Just destroy it on touch

#

CollisionOnEnter( Collision other) {
Destroy( gameObject );
}

paper osprey
night burrow
#

Please @paper osprey, read the Unity documentation on the OnCollisionEnter message and think about how to implement it with the information given there.
"How to destroy objects on collision" is an incredibly simple problem, one that several tutorials (and likely also StackOverflow threads) would have talked about.

I certainly do not mean to discourage you. But programming is about problem solving. You need to be able to look things like that up for yourself. Or at least be able to figure out how to use something - more so after several people have pretty much given you the code you need, and somewhat explained what to do with it.

paper osprey
#

sorry

harsh oyster
#

Ok i will start back
Destroy(collision.gameObject) This gameobject having this code can destroy other gameobject during collision but it will not destroy the gameobject having this code.
Destroy(gameObject) The gameobject having this code will be destroy during collision but will not destroy the other gameobject on collision

#

Understood now ?

paper osprey
#

i see