- Home /
Why does this raycast keep hitting itself?
I'm using a script from the wiki which i've slightly modified only to add a debug message. The purpose of it is supposed to prevent objects passing through walls at high speeds (because continuous collision detection is broken). The script is here: http://www.pasteall.org/56737/c
I've attached it to a cannonball. Here is a shot of it, and the inspector.
Important things to note here: 1. The cannonball is on layer ProjectilesFriendly 2. In the don't go through things script, Projectilesfriendly is set as the layer mask 3. the cannonball has no children or parents, its a lone object.
And finally, here's my Physics section of the project settings:
http://gyazo.com/6178982ddfd1c013d86ac81644f3704a
What's important to note here is that the ProjectilesFriendly layer doesn't collide with itself.
So i'm confused, why wont this work ?
Also i have no idea what went wrong with embedding images in this post. Please click the links to see them
Take a look here. Also when u pass the direction to the raycast you should normalize it.
Why layer$$anonymous$$ask.value and not just layer$$anonymous$$ask?
And what actually is the number you've put in it? What are the actual layers of the things you specified, numerically?
Are you firing it from inside a collider?
@melkorinos: Now done, but it didnt fix the problem.
@$$anonymous$$eat: I don't know, i didn't write it, i didnt make that decision.
The layer numbers:
I believe it's NOT being fired from inside a collider. Because it's firing from the position the object was in last frame, to the position its in now. But the layermasking should stop it from hitting itself.
Answer by meat5000 · Feb 17, 2015 at 04:04 AM
I will say:
In the LayerMask field, place the layer of the object you dont want to go through; i.e the object you want to hit. The statement in the script comments is misleading and threw me off at first.
On a side note, Continuous Dynamic works well against mesh colliders for high speed collisions.
i think this is the answer. I'm not choosing a layermask here, i'm creating one by choosing which layers to hit. doh >.<