Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

How would you make a bullet go to the direction of the mouse?

I know cloning the bullet and stuff like that and GetMuse() but I'm not sure how to use mouse very well.Can I get an explanation or can you refer me somewhere

1 answer

✓ Accepted answer
local plr = game.Players.LocalPlayer
local mouse = plr:GetMouse()

local function computeDirection(vec)
	local lenSquared = vec.magnitude * vec.magnitude
	local invSqrt = 1 / math.sqrt(lenSquared)
	return Vector3.new(vec.x * invSqrt, vec.y * invSqrt, vec.z * invSqrt).unit
end

mouse.Button1Down:connect(function()
	if not plr.Character then return end
	local dir = computeDirection(mouse.Hit.p - plr.Character.Torso.Position)
	--'dir' is your direction.  Continue from here.
end)

1 comment

0

Thank you

This discussion is preserved as it was. New answers, comments, and votes are closed.