How to properly use raycasting for interacting with objects

Oh I didnt notice that.

honestly it would be neat if you set up an auto shotgun turret

Yeah I could do that no problem.

I just tried it and it is stupid overpowered

I noticed a problem on the shotguns. The script uses the accuracy values to both set the random spread, but also the angle of the entity itself, so its like the spread itself has inaccuracy. Thinking about how to fix this

Wait im not even sure if thats a problem, let me check. No, it doesnt cause any issues. I was going off my previous knowledge of where the little bullet tracer box should be going, but it operates differently now and its fine. Also, I added the turret you wanted.

Nice. Yeah the way shotguns are implemented now is that all the bullets are random, so you have to make sure the accuracy is always trash

I also fixed the grenades and rockets and stuff, and added your turret. Now I am just trying to make some sort of health system, and I am not entirely sure how to do that. The “translate -50000” was just a placeholder to make sure the code worked.

ooh you finally rigged up the grenade script to work with the new system? thats pretty cool.

Yes and the rockets and the artillery

I am currently frankensteining a bunch of scripts into one conglomorate script titled gun. Would it be possible to turn all of that raycast stuff into a function so it doesnt have to be copied everywhere? Also, ive been thinking and why do we even need the shotgun boolean? Would a gun with a bulletcount of 1 with shotgun enabled act any differently than if it were disabled? If so we can skip the check and always have the gun technically be a shotgun but most guns would have a bulletcount of 1.

Yes, you can move all the raycast stuff to a function. It would work perfectly fine to have every gun technically be a shotgun just with one bullet.

I am currently working on the crouch system. The crouching works, but there is nothing stopping the player from standing up where they should not. So either I check the height with some raycasts or a collision, but I am not sure if there is a system to have a constantly checking trigger.

Just do the raycast whenever the player tries to stand up

Thanks man, now that I understand how to use raycasting I made a working system.