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

make part rotate to cursor?

Asked by 5 years ago

i want a part to rotate to cursor via Orientation; no CFrame witchcraft. can anybody help me with this?

1 answer

Log in to vote
1
Answered by
ee0w 458 Moderation Voter
5 years ago

Eh, you need some CFrame witchcraft. But it's fairly simple to do!


One of the constructors of a CFrame is as follows:

CFrame.new ( Vector3 Position, Vector3 LookAt )

For example:

CFrame.new(Vector3.new(0, 10, 0), Vector3.new(5, 0, 0))

Will create a CFrame located at {0, 10, 0}, oriented towards {5, 0, 0}. And that's all! Now all that's left is to plug in what you know already:

-- Local script
local mouse = game.Players.LocalPlayer:GetMouse()
local part = workspace.Part

mouse.Move:Connect(function()
    part.CFrame = CFrame.new(part.Position,mouse.Hit.Position)
end)

Hope I helped!

0
well TheluaBanana 946 — 5y
0
ok TheluaBanana 946 — 5y
0
well i need the orientation mainly for the fact that im doing a CFrame free game but thanks anyways TheluaBanana 946 — 5y
0
accept the answer plox ee0w 458 — 5y
View all comments (6 more)
0
im sorry dude TheluaBanana 946 — 5y
0
but it needs to b without cframe TheluaBanana 946 — 5y
1
U simply cant. ee0w 458 — 5y
0
Would you rather make an algorithm to point a rotation vector at a position vector? I don't think so. `CFrame.new(pos, look)` is as easy as it gets. ee0w 458 — 5y
0
actually yes TheluaBanana 946 — 5y
0
its not for performance or anyting its a personal challenge. if u dmonstrate what u said ill accept it TheluaBanana 946 — 5y
Ad

Answer this question