So im making a top-down survival game with guns. My problem is I want the gun to be accurate. What I’ve tried so far is getting the cframe of the gun but it’s not really accurate. If I use the hit cframe of the mouse , the bullet goes in the ground. Is there a way to reset that specific axis? Any help is appreciated! Here’s my module script:
local module = {}
local debris = game:GetService("Debris")
local ts = game:GetService("TweenService")
function module.CreateBullet(plr : Player, weaponProperties, mouseHit)
local char = plr.Character
local gun = char:WaitForChild(weaponProperties.Name)
local hitbox = Instance.new("Part", workspace.Bullets)
debris:AddItem(hitbox, 1)
hitbox.Size = Vector3.new(200, .5, .5)
hitbox.Transparency = .75
hitbox.Anchored = true
hitbox.CanCollide = false
hitbox.CFrame = CFrame.lookAt(gun.Position, mouseHit.Position) * CFrame.Angles(0, math.rad(-90), 0)
hitbox.CFrame *= CFrame.new(-hitbox.Size.X / 2, 0, 0)
--[[local bullet = Instance.new("Part", hitbox)
bullet.CFrame = gun.CFrame
bullet.CanCollide = false
bullet.Anchored = true
bullet.Size = Vector3.new(.5, .25, .25)
bullet.Material = Enum.Material.Neon
bullet.Color = Color3.new(1, 0.968627, 0.0392157)
ts:Create(bullet, TweenInfo.new(1, Enum.EasingStyle.Sine), {CFrame = bullet.CFrame * CFrame.new(-hitbox.Size.X, 0, 0)}):Play()
]]
end
return module
(Ignore the bullet section)