Hello!
I have this script attached to my bullet object that is supposed to destroy it when touching a Collider, and Instantiate a particle.
The problem is that the bullet goes so fast, that the particle Instantiate not exactly the same time when the bullet collides, but a bit later, after the bullet has changed its direction from the hit, because the OnCollisionEnter function doesn’t destroy the bullet on time…
#pragma strict
var DirtHit : GameObject;
function Start () {
rigidbody.AddRelativeForce (Vector3.forward * 1000);
yield WaitForSeconds(3);
Destroy(gameObject);
}
function OnCollisionEnter (other : Collision) {
Destroy(gameObject);
Instantiate(DirtHit, transform.position, transform.rotation);
}
It has a cube collider, if this helps…
Thanks! But how I will insert the raycast on my script? It will be on the bullet or the gun?
– smirlianosRaycast from the bullet. If you search youtube for "Unity Bullet Holes" you should get a few good tutorials, even though you're not doing bullet holes the principle is very similar.
– Hamesh81