#it is part of the bullet prefab and Play

1 messages · Page 1 of 1 (latest)

runic sentinel
#

is this code attached to your prefab?

arctic quarry
#

yes

runic sentinel
#

but it is destroying correctly?

arctic quarry
#

it is destroying the bullet correctly

runic sentinel
#

ok that's weird

arctic quarry
#

ok

runic sentinel
#

can you show the code for explode?

arctic quarry
#

so I forgot to untick the play on awake

arctic quarry
#

private void explode()
{
if (!explosion.GetComponent<ParticleSystem>().isPlaying)
{
explosion.GetComponent<ParticleSystem>().Play();
}
}

runic sentinel
#

well, at least you found it out 😆

arctic quarry
#

now it does not play at start but still does not play on collision

runic sentinel
#

try removing your first condition

#

or put Debug.Log just after to check if it enters the condition

arctic quarry
#

the if?

runic sentinel
#
private void explode()
    {
        if (!explosion.GetComponent<ParticleSystem>().isPlaying)
        {
            Debug.Log("Enter Condition");
            explosion.GetComponent<ParticleSystem>().Play();
        }
    }```
arctic quarry
#

ok let me see

runic sentinel
#

now i'm not super fluent on the particle system it seems to have its quirks

arctic quarry
#

yes, yes it does

runic sentinel
#

okay so it's really the play function that has a problem somehow

arctic quarry
#

ok there is a log message

#

but no explosion

runic sentinel
#

so it has to do

#

ah sorry

#

with the way it's attached as a component or on your prefab

arctic quarry
#

hmm

#

it is weird

#

I have a another particle attached to my player it works fine

runic sentinel
#

i'm under the feeling it's getting messed up by the instantiations

arctic quarry
#

perhaps

#

I will double check its properties

#

beacuse I have another particle for the player and the code is pretty much the same for it but it works fine

#

then agai the player is not instantiated so....

runic sentinel
#

also always double condition with && thingie.GetComponent<T>() != null

#

it helps you debug if the component got lost or anything abnormal is going on

languid moth
#

You can also just add a script on the bullet and check for a collision. If it hits a gameobject, instantiate the explosion

runic sentinel
#

yeah i'd do it from outside tbh

#

but i understand the handiness of having it on a prefab

languid moth
#

You can also do it the other way around, and have a script on the object and check if a bullet hits it, if so instantiate an explosion on the bullets transform

runic sentinel
#

i guess that depends if it should explode when colliding on anything or just these specific targets

languid moth
#

yea

runic sentinel
#

cute snek btw 🙂

languid moth
#

if you want it to explode on multiple different things you should just add the script on the bullets

languid moth
#

lmao

runic sentinel
#

cute herpeto thingies, ha 😂

arctic quarry
#

if the bullet hits the cornet and the explosion plays in the middle it won't look good

languid moth
#

Let me write an example

arctic quarry
#

there is thing called ContactPoint in unity but it was too complicated for something so basic

languid moth
#

Here's a script that's supposed to be on the object thats being shot at: ```c
public void OnCollisionEnter(collision col){
if(col.CompareTag("bullet")){ //Make sure you have a bullet tag on the bullet
// Instantiate explosion
Destroy()
}
}

arctic quarry
#

I just need to make the particle work and it would be fine

languid moth
#

You can then instantiate the explosion, and then destroy the object

arctic quarry
languid moth
#

What was the error?

arctic quarry
#

uhh...

#

wait no that was for something else

#

lemme do that again actually

#

hold up

languid moth
arctic quarry
#

like how do I kill them now

languid moth
#

Can you share a ss? I dont understand what you mean

languid moth
arctic quarry
languid moth
arctic quarry
#

there are explosion gameobjects now

languid moth
#

Ohh I see

arctic quarry
#

they play on the bullet collision which is fine they do not play afterwards

#

and just stay there

languid moth
#

Yea you need to destroy those too

arctic quarry
#

wait

languid moth
#

You should just be able to Destroy() the explosion as well

arctic quarry
#

what if I say destroy after idk 2secs after the instantiate

#

would that work

languid moth
#

yea

#

that would work

#

just make sure you destroy it once the animation has completely finished

arctic quarry
#

something like this

languid moth
#

Why do you have a void for explode?

#

Where are you calling the function

arctic quarry
#

when the bullet collides

languid moth
#

hmm alright

#

test it out

arctic quarry
#

it works

#

they die after 2 seconds

#

but I am still having my first problem sometimes

#

the bullet does not collide

#

I will make the target thicker

#

that should work

#

Unity collision is confusing for me

#

especially when it is a mesh collider

#

😵‍💫