|
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:
Heres what happens:
Herewith my script attached to the "source":
I also tried Quite possibly, I'm missing something, and hope that someone more experienced will be able to give me an opinion/solution. All the best!
(comments are locked)
|
|
What do you want the object to do? If you want it to explode at first collision, use OnCollisionEnter. What is it colliding with? Very strange if OnCollisionEnter doesn't detect anything. Especialy since you say your spell bounces: each bounce should be detected. Try print(collision.gameObject.name) and if it doesn't give you the name of the object/surface your spell bounces off, your problem probably lies elsewhere. Try debugging with OnCollisionEnter(collision:Collider) as well, to narrow it down. Ah, one more thing: you say your script is attached to the "source", I hope that doesn't mean it just stays with the caster and hence doesn't travel with the spell object! Hi @gregzo, Thanks for the reply. With "print(collision.gameObject.name)", it does print the name of the object its colliding with, but again only sometimes, and again does not send the message or destroys itself. When using "OnCollisionEnter(collision : Collider)" i get an error saying "Script error: OnCollisionEnter - This message parameter has to be of type: Collision - The message will be ignored." The "source" object gets instantiated, basically duplicated with all the attached scripts and components, did check and script is there
Dec 13 '11 at 09:38 PM
Henri 1
Sorry for the typo, i meant OnTriggerEnter(coll: Collider) to check of you had some colliders unknowingly set to isTrigger.
Dec 13 '11 at 09:43 PM
gregzo
What do you mean by source? A parent object? In what object is the OnCollisionEnter function? Just making you check the obvious, sorry, but that's often where mistakes hide...
Dec 13 '11 at 09:46 PM
gregzo
No prob. Only have 2 colliders thus far. The world (mesh collider) and the instantiated object, none set to isTrigger. By source I mean the object that gets instantiated, as that object is not visible (renderer and emitter turned off), only the instantiated object (renderer turned on and emitter on upon instantiation). The "collision" script file is attached to my source object, and is included in the cloned object. Just created a plane with a box and relevant colliders, getting same problems, so my current world and its collider is not problematic
Dec 13 '11 at 09:59 PM
Henri 1
(comments are locked)
|
|
Just ran into the same problem and came up with a solution that works in my case. My collision was doing the same thing where it would work sometimes and other times it would not. In order to fix this, I had to make sure that both the collider and the object it was colliding with have a rigidbody in it. The problem came up more when one of the objects was already involved in another collision. Try that and let me know. Thanks man... it worked... never thought of that :)
Dec 14 '11 at 03:26 PM
Henri 1
But again some collisions are not detected (about 1 in every 20) :(
Dec 14 '11 at 03:44 PM
Henri 1
Try to change the collision method. If that does not work, post up some code. Maybe the object is skipping over the collision every so often. I'd slow the object down to see if this is the problem. If you need the object to travel fast, look into a ray cast to help determine to collision.
Dec 14 '11 at 10:29 PM
ChefZweegie
(comments are locked)
|
