Raycast not working

I am loosely following a Brackeys’ tutorial (Multiplayer FPS) but I’ve started deviating significantly as I gain some understanding. (Also just doing it as a single player) In this case, I’m modifying the shoot script in a couple ways. I’m instantiating rigidbody bullets with a force rather than pure raycasting.

I also found a script that raycasts from the bullet rigidbody as it travels for hit detection. The original script looked like it was designed to be on the rigidbody projectile, but I modified it to go into my shoot script which is on my FPScontroller gameobject.

The instantiation works well (spawns a cube from my gun weapon holder (actually a cam that’s a child of the weapon holder, though I’m not sure if this makes sense? I’ve briefly thought about the best solution for making sure that the bullet spawns from the center of the barrel across multiple gun models, but I haven’t gotten that far.) with what looks like the correct force/velocity vector, etc.) but the raycast just doesn’t seem to work. I have a Debug to write the collider that got hit, but nothing. I have the layermasks set to everything. It seems weird to me that at the very least the ray isn’t hitting the collider of the cube I’m spawning in? (Yes, they have colliders) I even removed the if (stepsize), all the variables about stepsize, just left the if(raycast) just to try to get it to drawn any kind of ray. Changed distance in the raycast to infinity, etc. I’m stumped. I have a really great cube generator right now.

I also managed to break my weaponmanager script when I changed the ray casting. Previously when I started the game I instantiated a weapon which had a prefab attached, but I think that might be a different root cause.

Uploading all my scripts. Any other feedback is appreciated. I’m a complete noob.

3609677–293386–WeaponManager.cs (728 Bytes)
3609677–293387–PlayerShoot.cs (2.31 KB)
3609677–293388–PlayerWeapon.cs (257 Bytes)
3609677–293389–FirstPersonCharacterController.cs (10.7 KB)

I managed to fix my weaponmanager. So now I have a really sweet sci-fi cube generator. No luck on the raycast.

Update: I figured out how to do debug raycasting…… It appears if I put the ray inside the if {stepsize > 0.1}, it no longer casts. I’m sure it has something to do with converting it to be a script on the controller instead of the projectile, but I still can’t figure it out.

I think the issue is that the ray is only being cast once during the shoot method, instead of continuously. I need to draw the ray every frame. Now to figure that out…