Im currently working on a topdown shooter where the player is a sort of tank. I can move around and shoot and now im adding some particle effects. The effects do work but im having a problem.
When the player clicks the left mouse button it wil shoot a bullet. The bullet leaves some fire ( particle effect ), but the problem comes when i wanted to have an explosion when the bullet collides with something.
Actually this works fine to…
but it also shows the explosion in front of the tank when shooting
As you can see it also shows an explosion in front of the tank.
Here is also my code that is attached to the bullet
// the explosion particle effect
var explosion : GameObject;
// the tank
var speler : Transform;
function OnCollisionEnter( collision : Collision )
{
var contact : ContactPoint = collision.contacts[0];
var rotation = Quaternion.FromToRotation( Vector3.up, contact.normal );
var explosion : GameObject = Instantiate(
explosion, contact.point, rotation );
Destroy( gameObject );
}
function Update ()
{
// ignore the collision with the tank so there shouldn't be a explosion in front of the tank :(
Physics.IgnoreCollision(transform.collider , speler.collider);
}
im getting the idea the problem is not with collision but with the particle effect itself ?
can i maybe turn off that it automatiacly emits the particles on spawn ?
NullReferenceException: The prefab you want to instantiate is null,
UnityEngine.Object.Instantiate (UnityEngine.Object original, Vector3 position, Quaternion rotation)
I think this was in the FPS tutorial on how to prevent the rocket launcher’s rocket from blowing up itself when shooting.
// Ignore collisions between the missile and the character controller
Physics.IgnoreCollision(instantiatedProjectile.collider, transform.root.collider);
It’s only colliding with one object, so it’s likely a particle issue, and not a collision issue. Perhaps you are accidentally placing the explosion particle before you move it to the desired location…