How would i make it so the raycast goes in a straight line from where the gun is positioned,instead of using mousepos?

Hello
How would i make the gun fire from the local scripts barrel position instead of the mouse pos?


something like this,but by getting the gun position from the local script instead of its server position,as i have a point aim mechanic on the clients side.

this is how it fires from the client btw.

if semiDebounce == false then
semiDebounce = true
remotesFolder.Shoot:FireServer(mouse.Hit.Position, tool.Handle.Muzzle.WorldPosition, tool.Handle.CFrame)
wait(fireRate)
semiDebounce = false
end

and the server

for pellets = 1, pellets do
local randomSpread = Random.new():NextNumber(1.75, 2.25)
local direction = applySpread((mouseHitPos - localWorldPos).Unit, randomSpread)
caster:Fire(
localWorldPos,
direction,
1000
)
end

Assuming that this is where the mousepos is you can just change that to the sent handle CFrame.

I think it’d be as simple as making the CFrame of the bullet object where the end of the gun is.

In the recent game jam I did this on the client by using a part where the end of the gun is, but ran into issues with connecting that to a modulescript for an enemy. I’m sure putting the code in a normal script instead would’ve fixed it.

Anyways, doing the spawning on there server gives a little big of lag so it makes it seem like it’s not going where it should. I recommend doing it on the client for that, but with the example I gave above, you might need to rewrite or move other code.

i tried doing that but the gun was shooting at angle even tho the thing itself was perfectly straight

1 Like

Maybe try rotating the part until its straight? Could be a temporary solution.

that would not work,it would negate the entire point aim system

Make the cframe position the part and then the lookvector of the same cframe based on the mouse location/direction?