Is this a good idea for a raycast gun?

Here’s how it works currently, the raycast fires from the player’s humanoidrootpart to the mouse’s position. Originally, I did this because let’s say the player is behind a wall. If I fired the raycast from the barrel of the gun they could just stick the gun off the wall and shoot the player that way. Whereas with the humanoidrootpart they can’t.

2 Likes

It is fine, but sometimes the RootPart is being blocked by a part in front while your head isn’t, so if you try to shoot, it wont work so you should shoot the ray from the Player’s Head, instead.

Ah alright then. Thank you. Thanks.

it’s actually is better practice to shoot a ray from a part such as the HRP or head, or the camera for FPS. Shooting from the actual barrel can make an offset which I have noticed in games that do this method and can affect the users aim.

For my gun system I raycast from the head, while doing the effects on the barrel.

I was wondering about the head though, could the position change depending on the player’s avatar? Or nah? I assume no but just checking.

For all intents and purposes (atleast from a raycast perspective), not to an extent that you would need to worry about it.

Oh alright, well thanks guys. One more question though, would it be better to parent a server-script to the starterpack tool and do the stuff there? Because I was thinking that may be very consuming on resources since if you had 10 players that’s like 10 server-scripts. Or should I instead make a local script and make calculations on the server when I need to, and then fire to all clients from the server to create the visuals of the raycast?

I’ve had this topic come up before and the general consensus with raycasts is to do them solely on the client and send to the server when something needs to be replicated.

Obviously this does cause some issues with exploit vulnerability, however you can mitigate this with sanity checking.

Yes, but I also meant in general. Is it usually better to parent a server-script to starterpack or a local script to starterpack? I know it sorta depends but a usual answer?

Localscript, as you’re doing it on the client.

You’d want:
One server script in ServerscriptService for the damaging/replicating
One local script in StarterPlayerScripts for rendering replicated effects
One local script in the gun(s) [could use a hopper system] for handling the gun.

Obviously you could go into more detail and use a shared module for rendering but for your current situation, the above layout would be fine.

Yes I know in my situation client-scirpt would be better but, I meant as in general. Like tools in general, not just my situation. Like other situations, what’s usually the best course of action? Client script parented to starterpack (communicate to server via remotes) or server-script parented to starterpack?

Client script always. Having a server script for each gun is unnecessary (especially if the gun is just shooting etc) as all effects can be handled on the client and sent with remote events.

I’m sorry if im stupid or sound annoying but, I know for guns its best to do client-scripts but I meant in general. Like for other types of things too, like flashlights or whatever. Best course of action either client or server?

Its a case by case basis but ultimately a centralised tool framework would have one serverscript for handling the server side and the client scripts in the individual tools communicating with that script.

Anything you do on the server script in a tool you could do as a server script for all the tools with only a tiny bit of changing - this means that it’s easier to read and easier to change.

Alright then thank you, I’ll mark the topic as solved.

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.