- Home /
Instantiate Explosion Position
I have a problem with Explosions of the enemy... When the enemy is destroyed, I want to instantiate particles as a prefab, and everything works fine, but it explodes far away from the enemy :\ That`s the problem.. Can you help me please? I sure there is some mistake right there in instantiate position....
public GameObject enemyexplosion;
// Use this for initialization
void Start () {
}
// Update is called once per frame
void Update () {
}
void OnCollisionEnter(Collision c){
if (c.gameObject.tag == "Player") {
Destroy(c.gameObject);
Instantiate(enemyexplosion, transform.position, transform.rotation);
Destroy(gameObject);
}
}
}
Is this script on the enemy object? If not, the transform.position
you're using will be that of the object the script is attached to.
If this script is attached on the enemy object and this is still not working. Try to use transform.localPosition ins$$anonymous$$d transform.position
Answer by IlanaBrenner · Jul 22, 2015 at 03:21 PM
Thank you guys, but i found the problem. I attached the script to bullet that killing it and not to the enemy and it works. :)
Answer by TonanBora · Jul 22, 2015 at 03:55 PM
Hello Ilana. If this script is not attached to the actual enemy, you will want to get the enemy's position and use that during instantiate.
Also, you might want to check the prefab's position in the project window, and if it is not all zeroed out, zero it out.