Good day everybody!
Hope all is well
I’m having some problems with my simple collision script, and was wondering if I’m doing it the right way.
Heres the scenario:
-
Have a “spell” which my player casts, it instantiates a gameObject with a particle system, light, collision script, rigidbody, sphere collider and detonator attached to it (Sphere collider disabled on “source”, and enabled once “cast”)
-
When my player “casts” the spell, everythings works 100% except for the collision sometimes.
-
My rigidbody’s collision detection is set to “Continues Dynamic”, does not make a difference when set to “Dynamic” or “Discreet”
-
I require the rigidbody in order to add force for the spell to move in the direction shot
Heres what happens:
-
The instantiated object does bounce off my world (meaning the collision is working)
-
Sometimes it does print “Hit” to the console, but does not explode
-
Sometimes it prints “Hit” and explodes, but does not detroy the object
-
Sometimes it does not print or explode, but destroys itself
-
Sometimes it prints, explodes and destroys.
-
Angle/direction the spell is cast in does not effect the result.
Herewith my script attached to the “source”:
function OnCollisionStay(collision : Collision) {
print ("Hit!");
SendMessage("doExplode", SendMessageOptions.RequireReceiver);
Destroy(gameObject);
}
I also tried OnCollisionEnter
but does not detect anything.
Quite possibly, I’m missing something, and hope that someone more experienced will be able to give me an opinion/solution.
All the best!