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

Making a part point in the direction of the mouse?

Asked by 8 years ago

I made this, so far all it does is rotate randomly around the place. How can I make it so it will only rotate up and down?

local plane = game.Workspace.Union
local player = game.Players.LocalPlayer
repeat wait() until player.Character
local character = player.Character
local mouse = player:GetMouse()

while true do
    wait()
    plane.CFrame = CFrame.new( plane.Position, Vector3.new(-90,-90,mouse.Hit.p.Z));
end
0
The Y-Axis is vertical. XAXA 1569 — 8y

2 answers

Log in to vote
2
Answered by
DevSean 270 Moderation Voter
8 years ago

You want the plane to ignore the mouse's Z position, to do this you supply the Vector3 with the planes Z position.

    plane.CFrame = CFrame.new(plane.Position, Vector3.new(mouse.Hit.X, mouse.Hit.Y, plane.Position.Z))

The full code is supplied below, I've also add mouse.TargetFilter so the plane wont try to point at itself.

local plane = workspace.Union
local player = game.Players.LocalPlayer
repeat wait() until player.Character
local character = player.Character
local mouse = player:GetMouse()
mouse.TargetFilter = plane -- Optional so the plane wont try point at itself

while wait() do
    plane.CFrame = CFrame.new(plane.Position, Vector3.new(mouse.Hit.X, mouse.Hit.Y, plane.Position.Z))
end

Althought TheDeadlyPanther's script will work it will result in the plane pointing either vertically upwards/downwards (Which I don't think you want?)

1
Thank you for explaining it for me. UniversalDreams 205 — 8y
Ad
Log in to vote
0
Answered by 8 years ago

You're doing it wrong, so just do the following:

plane.CFrame = CFrame.new( plane.Position, Vector3.new(plane.CFrame.X,hit.p.Y,plane.CFrame.Z); -- if you want something to be the Y axis, keep it on the Y axis only

Hope I helped :)

~TDP

1
Thanks. UniversalDreams 205 — 8y

Answer this question