I'm currently working on a battle game that uses vehicles. However, I want to change the player's camera once they sit on the VehicleSeat to a different part of the Vehicle. How can I do this? Thanks in advance.
COMMUNITY QUESTION
How do I modify Camera position in a vehicle?
1 answer
The trick is the CameraSubject.
Here's a little code that can get you started(copied from the wiki)
local seat = script.Parent -- seat location
seat.Changed:connect(function(property)
if property ~= 'Occupant' then return end
local occupant = seat.Occupant
if occupant then
local character = occupant.Parent
local player = game.Players:GetPlayerFromCharacter(character)
if player then
-- Here, you can mess around now with the player. It is, or atleast I reccomend cloning a localscript into the player's startergui or backpack which will change the camera.
-- script.cameraScript:clone().Parent = player.PlayerGui
end
else
print("Someone left the seat") -- can't get the player here
end
end)
Inside the cameraScript things get tricky. What you actually need to is to only set the CameraSubject to the designated part and then going back to normal when the player gets up from the seat.
Getting the part what to focus is relatively easy, you can take advantage of the Humanoid.SeatPart property which works just like an ObjectValue. Making the camera go back to normal, you could use the Humanoid.StateChanged event.
This discussion is preserved as it was. New answers, comments, and votes are closed.
