I’m loosely following a Brackeys’ tutorial (actually getting more and more loose, FPS) and I’m sorta stuck.
I didn’t really like the way he did shooting, so I’ve changed it significantly. Overall goal is to instantiate a rigidbody, shoot it out with some force, have it shoot a raycast the distance it will travel between frames for hit detection. In case the question comes up, the reason why I’m not just doing raycast is that 1) I’m mostly just doing this to learn 2) I anticipate having multiple projectile types, most of which probably won’t work with simple raycasts.
My code right now does all of those things except it won’t continuously cast rays. Originally I had it in the Shoot method, but it wasn’t getting called continuously. Then I put it into a coroutine, but I’m pretty new so I’m not sure how to construct that. The coroutine works, but it only casts one ray. Probably because I’m not returning what I need to return in order to have to run again until collision is detected.
EDIT: I moved the collision detection to a separate script that is on the bullet gameobject. I can raycast outside of both of the if statements using the same arguments that are in the if{Physics.raycast}, but if I go inside the if statements it doesn’t work.
I can’t figure out what’s causing the if statements not to work.
On top of that, I’m not 100% sure on the math for the raycast if/else function.
Interestingly, the DrawRay code is inside the if(raycast) but so is a debug.log that should return the name of the collider that was hit, but nothing is being returned.
I attached all the of the code in a .txt file.
[123365-fullscript.txt|123365]