- Home /
OnTriggerEnter - Explosions that appear on the surface of hit object
Hello,
I have some fireballs that need to explode on contact with an object. However sometimes they seem to explode a bit behind the surface of the object.
Is there a way to specify the position of the explosion to be at the outside of the object?
Thanks!!
function OnTriggerEnter(other : Collider){
if (other.gameObject.layer != gameObject.layer)
{
var newExplode = Instantiate(explosionPrefab, transform.position, Quaternion.identity);
Destroy(gameObject);
}
}
what do you mean by 'a bit behind the surface of the object'?
if you want the explosion to appear a bit nearer to the camera I guess you can use:
Vector3 explosionPosition = transform.position + x * (camera.main.position - transform.position).normalized;
where x variable is set to whatever distance it needs to be
Answer by HarshadK · Dec 10, 2014 at 08:06 AM
You can get the closest point on the bound of the collider of object to get a point on the surface of your object and then instantiate your explosion prefab at that point.
Your answer
Follow this Question
Related Questions
Collision Detection without a RigidBody 2 Answers
Collision not detected 3 Answers
Collision problem in C# 4 Answers
2 objects collide, need to destroy one 2 Answers