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

Rotate player to mouse position?

What would I use to rotate my player to where my mouse is looking? I have no idea where to start.

1 comment

0

You can lock the player in first person, otherwise I believe it is up to the player to have MouseLock enabled.

1 answer

✓ Accepted answer

To do this you would have to use one of the CFrame constructors. You can see a full list here. There is one constructor, that takes two arguments. The first argument is the Vector3 Origin, or where your going to be starting from. the second argument is the Vector3 look at point, or where you're going to be looking at. So to do what you're trying to accomplish, we need to use this CFrame constructor on your character with a starting point of your character's position, and a look to point of your mouse's hit position.

local player = game.Player.LocalPlayer --Player
local mouse = plr:GetMouse --Player's mouse.
local char = plr.Character.Torso --Player's torso.

while wait() do
	local dir = (mouse.Hit.p - char.CFrame.p).unit * 100 --lookat point
	char.CFrame = CFrame.new(char.CFrame.p,dir)
end

3 comments

0

Is it possible to make it so the player does not move depending on if you look up or down, only if you look side to side, it rotates?(the Z and X values)

0

Yes but that's going to require an entirely different method.

0

At the end of line 6, what does .unit do?

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