Back again, more problems
After completing and ironing out all the problems with making a collider based projectile and handling the damage across game objects, I realized as so many do. Fast moving collisions donāt work. Kinda wish I was warned, but it lead to some extremely useful knowledge so Iām happy for the experience.
Moving along, I started to learn about ray casting. But I have some questions about it, and how to apply layer masking to it. Heres my code first.
var hit = (Physics.Raycast (transform.position, target, range));
if (hit != null) {
var testhit = hit.GetComponent(test);
if (testhit != null) {
print("Companion Cube in sight!");
}
}
Now as you can plainly seeā¦ I havenāt gotten far. I was using code whoās sintax I cannot seem to fathom using the lovingly emblished reference material. I thought I was applying a layer mask to variable testhit. The layer I was trying to restrict to was test. The only object in my test environment that has the layer test is a cube named āCompanion Cubeā. But it was sorta a failure on the debug check. Kept spitting the same mumbo jumbo that every programmer I know hates. Error code: Something~in~greek
So moving along. What I need help with is the sintax involved. If you could show me my trouble spots using the same variables I used. (When people use cookie cutter expamples I get very lost as to what is a function/var/expression/blackmagic etc.)
Also, layer masks seem to be Exclusive only from what Iāve read (Which really makes me feel my code is fragged) is there a way to write it so that I donāt have to isolate the layer mask as a variable and invert it with the whole var = ~var expression?
Iām fairly confident that once I understand the layer mask sintax, so I can restrict the contact of my ray-caster unity will stop having a hissy-cow about unexpected Boolean nonsense.
Next question Iām fairly sure is in-depth. Raycasting appears to cast the ray as far as the distance its marked for. Returning everything it bashes into (Maybe Iām totally wrong there, Sorry if I am please set me straight). But I donāt want all my bullets to be piercing. Iād like to be able to restrict the selection to the first, second, third, All, objects it collides with, in order. This way I can add targetās pierced. Or all. Or simply stop on the first target. Is there a way to isolate and restrict this or pick it apart as usable information?
On the flip side, if ray-casts donāt push beyond the first collision, how am I to accomplish piercing bullets?
I know this is a lot of questions honestly, but they are all the same two subjects in the heading, and I feel splitting all this information up would cause me to lose sight of the concept as a whole. Thanks for reading if you got this far and havenāt given up on me!