Hi there!
-
What do you want to achieve? I am working on my battle system and want to create a lock on system so that players can lock onto a target and not worry about moving their camera (Like in SoulShatters)
-
What is the issue? Right now i have the lock system working for the character but with the method I have in place the camera gets unlocked from the character and the character kind of runs off the camera.
-
What solutions have you tried so far? I have tried looking into magnitude from my target, all over google, and the devforum.
Here is the code I have right now.
local Cam = workspace.CurrentCamera
local Players = game:GetService("Players")
local RunService = game:GetService("RunService")
wait(1)
local player = Players.LocalPlayer
local Character = player.Character
repeat
workspace.CurrentCamera.CameraType = Enum.CameraType.Scriptable
until workspace.CurrentCamera.CameraType == Enum.CameraType.Scriptable
local function UpdateCam()
local CFam = CFrame.new(script.Parent.Parent.Character.PrimaryPart.CFrame.Position, workspace.Dummy.PrimaryPart.CFrame.Position)
local CamCFam = CFrame.new(
Vector3.new(script.Parent.Parent.Character.PrimaryPart.CFrame.Position.X - 5, -- X
script.Parent.Parent.Character.PrimaryPart.CFrame.Position.Y + 3, -- Y
script.Parent.Parent.Character.PrimaryPart.CFrame.Position.Z - 5), -- Z
workspace.Dummy.PrimaryPart.CFrame.Position -- Lookat
)
workspace.CurrentCamera.CFrame = CamCFam
script.Parent.Parent.Character:SetPrimaryPartCFrame(CFam)
end
RunService.Stepped:Connect(UpdateCam)
It works with no and as expected until i start moving and changing my Z axis coordinates
Here is how i want it to look
Here is a video showing how the Character just goes out of frame
robloxapp-20200815-1607438.wmv (3.7 MB) (Sorry about the file type)
If there is some sort of way to do the
script.Parent.Parent.Character.PrimaryPart.CFrame.Position.X - 5, -- X
script.Parent.Parent.Character.PrimaryPart.CFrame.Position.Y + 3, -- Y
script.Parent.Parent.Character.PrimaryPart.CFrame.Position.Z - 5 -- Z
without the X and Z drifting from the character that would be great!
Thanks
PS: yes i do know i am using CFrame.new instead of CFrame.FromMatrix (I am planning on changing that when i have a working test)