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

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

Asked by 9 years ago

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
Define 'Something', as in an actual 3D part or a GUI? DigitalVeer 1473 — 9y

1 answer

Log in to vote
0
Answered by 9 years ago

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.

Ad

Answer this question