Hey there
I am trying to achieve some things with a projectile:
- Destroy on collision -check
- Ragdolloze hit object -check
- leave the impact effect on object
- a. instantiate the impact effect -check
- b. at the hitpoint -check
- c. align impact effect with the surface - X
It is frustrating ,becouse the position is perfect and calculated from the hit.contacts contact.point,i just cant get the rotation to work.
Here is my code:
var impactEffect : GameObject;
function Start () { //auto destroy to prevent infinite projectiles
yield WaitForSeconds(2.0);
Destroy (gameObject);
}
function OnCollisionEnter ( hit : Collision){
Destroy (gameObject);
Debug.Log(hit.gameObject);
for (var contact : ContactPoint in hit.contacts) {
var ieffect = Instantiate (impactEffect, contact.point,transform.rotation); //rotation is a problem
ieffect.transform.parent = hit.gameObject.transform;
}
hit.gameObject.rigidbody.isKinematic = false; //ragdollize hit object
hit.gameObject.SendMessageUpwards("Ragdollize");
}
I tried using this :
var hitRotation = Quaternion.FromToRotation(Vector3.up, hit.normal);
But i just dont know how to get this to work.
Any help would be greatly appriciated.
Thanks