Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

Attempting to find camera.hit but not working? the question needs to be longer?

Asked by
HDWC 53
5 years ago

Im making a battle royale and im attempting to find the direction of the camera and the hit/position using a ray. Whenever I run the function the bullet is being shot right at the camera. I've tried diifferent stuff like Ray.new(camera.CFrame.Position, Camera.CFrame.LookVector) but nothing's working!

    local function Shoot(endpos, Start)

local bullet = Instance.new("Part", workspace)

bullet.Size = Vector3.new(0.1,0.1,(endpos - Start).magnitude)

bullet.Anchored = true

bullet.Material = Enum.Material.Neon

bullet.BrickColor = BrickColor.White()

bullet.CFrame = CFrame.new(Start,endpos)

bullet.CFrame = bullet.CFrame + bullet.CFrame.lookVector * ((endpos - Start).magnitude / 2)

game:GetService("Debris"):AddItem(bullet, config.FireRate / 4)

end

local function HandleShoot(_,_,input)

if config.FireType == "Auto" then

if input.UserInputState == Enum.UserInputState.Begin then

shooting = true

while shooting do

if shotdebounce then

shotdebounce = false

local ray = Ray.new(camera.CFrame.Position, CFrame.new(camera.CFrame.Position, player:GetMouse().hit.Position).Position )

local part, position = workspace:FindPartOnRay(ray, nil, true, true)

Shoot(position, gun.FirePart.Position)

gun.FirePart.Fire:Play()

wait(config.FireRate)

shotdebounce = true

else

wait()

end

end

elseif input.UserInputState == Enum.UserInputState.End then

shooting = false

end

end

end

Thanks!

Answer this question