It's not an FPS, but I want the player to be able to follow the mouse, like in Deadzone Remade.
So if the mouse is on the left of the screen, I want the player to be facing the left.
It's not an FPS, but I want the player to be able to follow the mouse, like in Deadzone Remade.
So if the mouse is on the left of the screen, I want the player to be facing the left.
First, this should be in a localscript, somewhere inside the player or player character.
CFrame
There's a neat little feature you can use in CFrame to create something that points in a given vector direction. We're also going to rotate the player by changing it's torso CFrame. So, let's make some references:
-- LocalScript
local Client = game:GetService'Players'
local Mouse = Client:GetMouse() -- get the player mouse
-- Returns the player character, or waits for it if it doesn't exist already.
local Character = Client.Character or Client.CharacterAdded:wait()
local Torso = Character:WaitForChild'Torso'
-- Now, let's make an event that will fire this function whenever the mouse moves. For this, we can use the "Move" event on "Mouse".
-- I'll go over this
Mouse.Move:connect(function()
Torso.CFrame = CFrame.new(Torso.Position, Vector3.new(Mouse.X,Torso.Position.Y,Torso.Position.Z)
end)
So, it's pretty clear CFrame is a dynamic concept. Using CFrame with these 2 Vector3 arguments, creates a rotated CFrame that points in the direction of the second Vector3's position. And of course, the first argument is the position it will stay in.
Note how we're also saying Torso.Position.Y, and Torso.Position.Z in our last Vector3, because we only want the character to look in 1 2D direction.
Hope this helped, let me know if you have any questions.
This discussion is preserved as it was. New answers, comments, and votes are closed.