I want to change the camera from focusing on the player to focus on the model that has a seat that the player is sitting on, how to go about it?
Any help appreciated!
I want to change the camera from focusing on the player to focus on the model that has a seat that the player is sitting on, how to go about it?
Any help appreciated!
If you mean the centre of the model, this should get the centre:
local totalPosition = Vector3.new(0, 0, 0)
local partCount = 0
for _, part in model:GetDescendants() do
if part:IsA("BasePart") then
totalPosition += part.Position
partCount +=1
end
end
if partCount > 0 then
print(totalPosition / partCount) -- that is the centre
end
Then you can just put a part at the centre:
local Part = Instance.new("Part")
Part.Transparency = 1
Part.Anchored = true
Part.Position = totalPosition / partCount
Part.Parent = Model
Camera.CameraType = Enum.CameraType.Scriptable
Camera.CameraSubject = Part
Then it (should) work!
Does CameraSubject allow for rotation when using right click? Similar to with your character.
My aim is to allow for cam rotation as well, just like when the cam is focused on the player’s character.
Make the camera subject be the humanoid
And if said model doesn’t have a humanoid? I don’t want some of these models to have humanoid physics.
the head of the model maybe? ???
Do you know or are you guessing?
It should as long as you set the Camera.CameraType back to Enum.CameraType.Custom after changing the camera
If that’s what you seek, don’t use the Camera Type Scriptable, instead use something like Watch or Follow.
Here’s some example code that does that:
local function StartTracking(Trackable : Model)
local VehicleTracker = Instance.new("Part");
VehicleTracker.Name = "_VehicleTracker"
VehicleTracker.CanCollide = false;
VehicleTracker.Parent = game.Workspace.CurrentCamera;
local WeldPoint;
if Trackable:IsA("Model") then
local PrimaryPart = Trackable.PrimaryPart
if not PrimaryPart then
return error("Please make sure",Trackable,"has a PrimaryPart set!") end
WeldPoint = PrimaryPart;
else
WeldPoint = Trackable;
end
VehicleTracker.Position = WeldPoint;
local Weld = Instance.new("Weld")
Weld.Part0 = VehicleTracker;
Weld.Part1 = WeldPoint;
Weld.Parent = VehicleTracker;
game.Workspace.CurrentCamera.CameraType = Enum.CameraType.Follow;
game.Workspace.CurrentCamera.CameraSubject = VehicleTracker;
game.Workspace.CurrentCamera.CFrame = VehicleTracker.CFrame + Vector3.new(0,10,10)
end
local function StopTracking()
local VT = game.Workspace.CurrentCamera:FindFirstChild("_VehicleTracker")
if VT then
VT:Destroy()
end
game.Workspace.CurrentCamera.CameraSubject = game.Players.LocalPlayer.Character.Humanoid;
game.Workspace.CurrentCamera.CameraType = Enum.CameraType.Custom;
game.Workspace.CurrentCamera.CFrame = game.Players.LocalPlayer.Character.Head.CFrame;
end
You can change the “Enum.CameraType” from Follow to something like Attach or Track to try out other camera modes.