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

How do I make "Scriptable" CameraType behave as if the Player is in first person?

So I'm making a custom camera/character system and to do this, I have to make the CameraType "Scriptable". However, by changing it to "Scriptable", the character does not always face the mouse anymore. Is there a solution to this other than BodyGyro(because BodyGyro is not instant)?

2 comments

0

Don't make a custom camera system.

0

Just set the CameraMaxZoomDistance property of starter player to 0. http://wiki.roblox.com/index.php?title=API:Class/StarterPlayer/CameraMaxZoomDistance

1 answer

You can set what a part is looking at using CFrame.

Example:

local position = Vector3.new(0,10,0)
local lookAt    = Vector3.new(10,10,0)

local part = script.Parent

part.CFrame = CFrame.new(position, lookAt)

This can be applied to the mouse as well.

--// Services
local Players = game:GetService("Players")
local RunService = game:GetService("RunService")

--// Local Variables
local plr = Players.LocalPlayer
local mouse = plr:GetMouse()
local char= plr.Character or plr.CharacterAdded:Wait()
local torso = char:WaitForChild("Torso")

RunService.RenderStepped:Connect(function()
	torso.CFrame = CFrame.new(torso.Position, mouse.Hit.p)
end)

You probably don't want them to look at the same Y axis as the mouse, though. So to fix that here's what I changed:

RunService.RenderStepped:Connect(function()
	torso.CFrame = CFrame.new(torso.Position, Vector3.new(mouse.Hit.X, torso.Position.Y, mouse.Hit.Z))
end)

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