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

Camera Won't face the Player when module is started(?)

Asked by 2 years ago

What I'm trying to do is start the player's camera off staring at the players face when the player spawns and then zoom out and do something cool but I'm struggling with making the cam face the players head then zoom out.

local mod = {}
local cam = workspace.CurrentCamera
local Tween = game:GetService('TweenService')
local Players = game:GetService('Players')
local RS = game:GetService("ReplicatedStorage")
local Player = Players.LocalPlayer
local S = RS:FindFirstChild('DuelOfTheFates')
mod.Camera = function(Player, key)
    if key == 1 then
        Player:WaitForChild(Player.Character)
        cam.CameraType = Enum.CameraType.Scriptable
        cam.CameraSubject = Player.Character.Head:FindFirstChild'FaceFrontAttachment'
        cam.CFrame = CFrame.new(Player.Character.Head:FindFirstChild'FaceFrontAttachment'.CFrame * Vector3.new(0,0,0))
    end
end

mod.Initialize = function()
    mod.Camera(1)
    local Sound = S:Clone()
    S.Parent = Player.PlayerGui
    S:Play()
end


return mod

1 answer

Log in to vote
0
Answered by
Speedmask 661 Moderation Voter
2 years ago
Edited 2 years ago

it looks good up until line 13. I don’t even think (although I’m not certain) that you can even multiply a cframe by a vector3, although you haven’t mentioned any errors. nonetheless, multiplying a matrix by (0, 0, 0) does just that: it sets everything to 0. I doubt that is your goal.

now, I am not certain what direction you are trying to go, but that part with the LookAttachment is not necessary. you can use Head.LookVector (unless you have some special logic that is different, then ignore what I said).

now for the actual answer. you can use CFrame.lookAt() to make the camera uh, look at something. to be honest, I’m not even sure what you are trying to do with your equation but here is a generic CFrame you could use.

local OFFSET = Vector3.new(x, y, z)
camera.CFrame = CFrame.lookAt(Head.Position + OFFSET, Head.Position)

this CFrame starts from the head, gets offset by a position through addition, and looks at the player’s head.

obviously I have not incorporated TweenService into this. if you know how to do that then go for it, if not comment and I will edit this post.

Ad

Answer this question