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

Help with raycasting?

Asked by 8 years ago

Check out this game, if you equip the tool, click on a cell that is the same color as your teamColor, then you should get a part following your mouse. I tried to do something like this, and here's what i got:

player = game.Players.LocalPlayer
mouse = player:GetMouse()

laser = Instance.new("Part",workspace)
laser.Anchored = true
laser.CanCollide = false
laser.TopSurface = "Smooth"

mouse.Move:connect(function()
    wait()
    local mag = (mouse.Hit.p-game.Workspace.Part.Position).magnitude
    local ray = Ray.new(
        game.Workspace.Part.Position
)
local part,pos = game.Workspace:FindPartOnRay(ray)
laser.Position = pos-Vector3.new(0,.4,0)
laser.Size = Vector3.new(1,1,mag)
end)

So two questions:

1) how do I get the direction

2) how to I get one end of the part to stay on game.Workspace.Part?

Answer this question