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

How to make something go in the directon of the cursor?

I'm kind of new to mouses. The only thing I pretty much know to mouses is how to do KeyDown. I'm not looking for a whole script, just tell me what I should do.

1 comment

1

Define 'Something', as in an actual 3D part or a GUI?

1 answer

To find the 3D position of the mouse, use mouse.Hit.p To make a part fly towards that position, you can use rocket propulsion, which is a BodyMover object.

As RocketPropulsion takes in an object, not a CFrame position, we'd need to make a part constantly go to the mouse's position.

This page offers good information on all the properties of rocket propulsion http://wiki.roblox.com/index.php?title=API:Class/RocketPropulsion

This page offers a simple explanation of how to get rocket propulsion working http://wiki.roblox.com/index.php?title=BodyMover_object#RocketPropulsion

To make a part with rocket propulsion in it start moving, use RocketPropulsion:Fire(), replacing RocketPropulsion with the name of the rocket propulsion.

Finally, you'd have a localscript inside the player that looks a bit like this

local player = game.Players.LocalPlayer
local mouse = player:GetMouse()
if mouse then
	local part = Instance.new("Part", game.Workspace)
	part.Name = player.Name.."MousePos"
	part.CanCollide = false
	part.Anchored = true
	part.Transparency = 1
	game.Workspace.Part.RocketPropulsion:Fire()
	while wait() do
		part.CFrame = CFrame.new(mouse.Hit.p)
		game.Workspace.Part.RocketPropulsion.Target = part
	end
end

Untested, sorry.

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