I am trying to make a telescope which you can hold E on a proximity prompt and it will transport your camera to ‘space’ and show you some celestial bodies. This script should just transport your camera to a new location (actual location would be implemented when I know it works) and you’d then be able to press E, or a gui button to return your camera back to normal. This does however not work.
local part = script.Parent
local function teleportCamera(player)
local character = player.Character
if character then
local humanoidRootPart = character:WaitForChild("HumanoidRootPart")
local camera = player.Camera
if camera then
camera.CameraType = Enum.CameraType.Scriptable
camera.CFrame = CFrame.new(0, 0, 0)
end
end
end
local proximityPrompt = script.Parent
proximityPrompt.Enabled = true
proximityPrompt.Triggered:Connect(function(player)
teleportCamera(player)
end)
local camera = workspace.CurrentCamera
local localPlayer = game:GetService("Players").LocalPlayer
local part = workspace.Part
local proximityPrompt = part.Attachment.ProximityPrompt
local function teleportCamera()
camera.CameraType = Enum.CameraType.Scriptable
camera.CFrame = CFrame.new(0,10,0)
-- ...
end
proximityPrompt.Triggered:Connect(teleportCamera)
It works! Thank you.
What do you think would be a good way to let the player know how to exit the camera view? I’m not that great at UI as my UI always breaks depending if you’re on mobile or not. Also, how do I add a way to exit the camera view?
Is it possible that any kind of key input or screen input would reset the camera afterwards? From the moment they press any key / click their mouse / tap their screen?
Once camera is scriptable, it’s in your control. In the camera modules, no controllers will be active. So a scriptable camera + CFrame change is sufficient. At least it always was in my projects.
All good. Soon you’ll see it’s rather simple. 1. CameraType → when scriptable, the control is ours; 2. CameraSubject → what the camera is focused on; 3. CFrame → while scriptable, it’s on us to update the position. In your case, it’s static, so just one set of a CFrame with the desired direction. For instance,
I noticed that when I was in the view, the proximity prompt stays, wouldn’t it be possible that when you hold E you can’t move anymore (so that you can’t walk away from the prompt and get stuck in the view) and then when you hold E again, you exit?
Absolutely, you can keep the player on the spot. Anchoring the humanoid root part would work, although I believe setting JumpHeight and WalkSpeed, and later restoring the values back to the original is quite neat for this use case.
The proximity prompt probably stays on the screen because it is on the view port and the humanoid stays in range. Sure, that works, although I prefer ContextActionService or button sollution.
I have modified the script to make your player not moveable anymore when you hold e
I have also added a button at the location which if you press makes your camera go back to your player, though you are not able to move yet.
local camera = workspace.CurrentCamera
local localPlayer = game:GetService("Players").LocalPlayer
local part = workspace.Telescope.Prox
local proximityPrompt = part.Attachment.ProximityPrompt
local function teleportCamera()
camera.CameraType = Enum.CameraType.Scriptable
camera.CFrame = CFrame.new(-31.618, -306.795, 359.889)
-- Disable character movement
local humanoid = localPlayer.Character.Humanoid
humanoid:ChangeState(Enum.HumanoidStateType.Physics)
end
proximityPrompt.Triggered:Connect(teleportCamera)
local clickDetector = workspace.Back.ClickDetector
local function returnCamera()
camera.CameraType = Enum.CameraType.Custom
camera.CameraSubject = localPlayer.Character.Humanoid
camera.CFrame = localPlayer.Character.HumanoidRootPart.CFrame
-- Enable character movement
local humanoid = localPlayer.Character.Humanoid
humanoid:ChangeState(Enum.HumanoidStateType.None)
humanoid:ChangeState(Enum.HumanoidStateType.Physics)
end
clickDetector.MouseClick:Connect(returnCamera)
EDIT:
I have removed the no more character movement from the script since i dont need it anymore. This script makes my view change when i hold e and teleports my camera back when i click something.
local camera = workspace.CurrentCamera
local localPlayer = game:GetService("Players").LocalPlayer
local part = workspace.Telescope.Prox
local proximityPrompt = part.Attachment.ProximityPrompt
local function teleportCamera()
camera.CameraType = Enum.CameraType.Scriptable
camera.CFrame = CFrame.new(-31.618, -306.795, 359.889)
end
proximityPrompt.Triggered:Connect(teleportCamera)
local clickDetector = workspace.Back.ClickDetector
local function returnCamera()
camera.CameraType = Enum.CameraType.Custom
camera.CameraSubject = localPlayer.Character.Humanoid
camera.CFrame = localPlayer.Character.HumanoidRootPart.CFrame
end
clickDetector.MouseClick:Connect(returnCamera)