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

Rotate player to mouse position?

Asked by 9 years ago

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

0
You can lock the player in first person, otherwise I believe it is up to the player to have MouseLock enabled. TheStudentPilot 75 — 9y

1 answer

Log in to vote
0
Answered by
Goulstem 8144 Badge of Merit Moderation Voter Administrator Community Moderator
9 years ago

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
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) killerkill29 35 — 9y
0
Yes but that's going to require an entirely different method. Goulstem 8144 — 9y
0
At the end of line 6, what does .unit do? killerkill29 35 — 9y
Ad

Answer this question