Hi, so to get to the point, I’m trying to make bullets shot from your gun aim toward your mouse cursor, simple right? I’ve achieved this before with my earlier guns but for some reason I can’t seem to figure out what it is I’m doing wrong.
Here’s a quick GIF of what I mean: https://gyazo.com/a5c063d1415d0e807d25e910a9389011
So you can see the bullet holes appear slightly to the left of the cursor, which creates massive problems for accuracy, i’m certain that my custom mouse pointer is centred properly (My regular mouse was spot on the crosshair), so I’m clueless as to what may be causing it
Here’s a code sample
On the client:
local function fire()
spawn(function()self:recoil()end)
local mouse = player:GetMouse()
if self.aiming then
self.events.fire:FireServer(self.weapon,self.settings.shooting.spreadaim,self.settings.shooting.damage,mouse.hit.LookVector)
else
self.events.fire:FireServer(self.weapon,self.settings.shooting.spread,self.settings.shooting.damage,mouse.hit.LookVector)
end
Server:
local origin = weapon.Barrel.Muzzle.WorldPosition
local direction = lookvector * 300 + Vector3.new(math.random(-spread,spread),math.random(-spread,spread),math.random(-spread,spread))
local rayresult = workspace:Raycast(origin,direction)
local endpoint
if rayresult then
endpoint = rayresult.Position
else
endpoint = origin + direction
end
local movespeed = (origin - endpoint).magnitude * 0.3 / 90
remotes.bulletVisualise:FireAllClients(origin,endpoint,movespeed)
there’s obviously more code for bullet holes etc, but I feel the problem is with the raycasting. Is lookvector not the way to go? Any help is massively appreciated!