Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
1

How do I modify Camera position in a vehicle?

Asked by 7 years ago

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.

1 answer

Log in to vote
0
Answered by
1N0body 206 Moderation Voter
7 years ago

The trick is the CameraSubject.

Camera Manipulation

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.

Ad

Answer this question