Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

Making a part point in the direction of the mouse?

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

1 comment

0

The Y-Axis is vertical.

2 answers

✓ Accepted answer

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 comment

1

Thank you for explaining it for me.

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 comment

1

Thanks.

This discussion is preserved as it was. New answers, comments, and votes are closed.