I created a trigger and added this. I was expecting to easily change from orbit to action and viceversa:
local CameraSwitchScript = {}
-- Script properties are defined here
CameraSwitchScript.Properties = {
}
function CameraSwitchScript:Init()
end
function CameraSwitchScript:OnTriggerEnter(player)
Print("Changing to action")
player.cameraType = 1 --action
end
function CameraSwitchScript:OnTriggerExit(player)
Print("Changing to orbit")
player.cameraType = 2 -- orbit
end
return CameraSwitchScript
It didn’t happen so.
For this to make it work, I had to change also cameraDistance in each of both methods.
local CameraSwitchScript = {}
-- Script properties are defined here
CameraSwitchScript.Properties = {
}
function CameraSwitchScript:Init()
end
function CameraSwitchScript:OnTriggerEnter(player)
Print("Changing to action")
player.cameraType = 1 --action
player.cameraDistance = 200 -- This number does nothing, as it always uses the 2000 value
end
function CameraSwitchScript:OnTriggerExit(player)
Print("Changing to orbit")
player.cameraType = 2 -- orbit
player.cameraDistance = 2000
end
return CameraSwitchScript
But changing cameraDistance affected the distance of the action camera, when it should not affect. This behaviour can be seen in this video: https://discord.com/channels/434318690381725726/728233736637775883/747384915158499328
I finally made it work with this ugly hack:
function CameraSwitchScript:OnTriggerEnter(player)
Print("Changing to action")
Print("Changing to action")
Print(player.cameraType)
Print(player.cameraDistance)
player.cameraDistance = 199
self:Schedule(function()
Wait(0.1)
Print("changing camera again")
player.forcedCameraPerspective = 3 -- 3rd person
player.thirdPersonFOV = 90
player.cameraDistance = 200
player.cameraType = 1
end
)
end
I would bet that the rendered value of the cameraDistance at the end is 199 (not 200), but it needs to be set so cameraType really changes. If I set to another value, it doesn’t reflect this last value.
It looks like this is related: Camera type and character speed issues
So, as a summary:
I think there are two different things: (1) the cameraDistance affecting the action camera; and (2) not being able to change the cameraType unless you change other property (cameraDistance)