hi guys,
i got a bullet impact script using raycastHit.point to find the place where to put my decals or sparks.
the problem is, when i press “fire” i dont even have the time to see the bullet it sparks immediately.
why ?
the script is there:
var bulletExplosion : Transform;
var point : Vector3;
var explosionRotation : Quaternion;
function Update() {
var hit: RaycastHit;
var fwd = transform.TransformDirection(Vector3.forward);
if (Physics.Raycast(this.transform.position, fwd, hit,1)) {
point = hit.point;
explosionRotation = Quaternion.FromToRotation(Vector3.up, hit.normal);
Explode();
}
}
function Explode(){
Destroy(this.gameObject);
var instanBulletExplosion = Instantiate(bulletExplosion, point, explosionRotation);
}
strangely when i use a “collision” script it works well, but the precision is terrible, so terrible that it dont even show the sparks 8 time on 10.
here is the “collision” code:
var explosion : Transform;
function OnCollisionEnter(collision : Collision){
if (collision.gameObject.tag == "decor") {
var contact = collision.contacts[0];
var rot = Quaternion.FromToRotation(Vector3.up, contact.normal);
var pos = contact.point;
Instantiate(explosion, pos, rot);
Destroy(gameObject);
}
}
can someone help me out ? to make the the raycast work properly or to make the collision script be more accurate.
thank you,
PARADOKS