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

How would I rotate this part so it's always pointing at mouse?

Asked by 8 years ago

I have this code:

local Camera = game.Workspace.CurrentCamera

local part = script.Part


game:GetService('RunService').RenderStepped:connect(function()
    part.Parent = Camera
    part.CFrame = Camera.CoordinateFrame * CFrame.new(0,-2,-2)
end)

Which puts a part in the screen so it sticks blah blah, and I want to rotate it so it's pointing at the mouse, because as of the code it just is pointing horizontally off the screen. What would I do for that?

1 answer

Log in to vote
0
Answered by
Perci1 4988 Trusted Moderation Voter Community Moderator
8 years ago

Your solution is really simple. Just use the CFrame constructor CFrame.new(Vector3 position, Vector3 lookAt).

--get the correct positioning
part.CFrame = Camera.CoordinateFrame * CFrame.new(0,-2,-2)

--rotate it, keeping the position we just set
part.CFrame = CFrame.new(part.Position, mouse.Hit.p)
0
part is equal to script.Part* Harrison_Ford 5 — 8y
0
Sorry. But my question remains, why would you have the part inside the script? If it's not in workspace, it won't be visible and if the script's in workspace it won't run. Perci1 4988 — 8y
0
actually the dude has the part inside of a camera??? also remember the script has to be a local script. AshRPG12 42 — 8y
0
Yeah FilteringEnabled should be used for local parts instead of those hacky methods, they may not work. Perci1 4988 — 8y
Ad

Answer this question