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

Vehicle Camera Focuses On Part?

Asked by 10 years ago

How would I get it so when a player is in a Vehicle seat, the players camera will focus on a part called Focus in the Vehicle instead of on the Vehicle seat? (As the vehicle is remote controlled in this case.)

0
You can change the CameraSubject property (Camera.CameraSubject = vehicle.Focus) or the Focus property (Camera.Focus = CFrame.new(vehicle.Focus.Position) I'm pretty sure what you're wanting to do is set the CameraSubject though. nate890 495 — 10y
0
I gathered that much but where to but the script and whith what activation i do not know. skunk940 10 — 10y
1
Does the player sit in the seat? (you say it's remote-controlled.) nate890 495 — 10y
0
Yes, they sit in the seat and they can controll the car (seat is not attached to car) but the camera stays focused on the seat. I want it to focus on the car instead. skunk940 10 — 10y

1 answer

Log in to vote
2
Answered by
nate890 495 Moderation Voter
10 years ago

This would require 2 scripts, a LocalScript and just a plain script.

Put the following code into a LocalScript and insert the script into game.Lighting:

local vehicle = game.Workspace.Vehicle
local camera = game.Workspace.CurrentCamera

if camera.CameraSubject == vehicle.Focus then
    camera.CameraSubject = game.Players.LocalPlayer
else
    camera.CameraSubject = vehicle.Focus
end

The following code goes in a Script

local seat = game.Workspace.Seat
local vehicle = game.Workspace.Vehicle

seat.ChildAdded:connect(function(child) -- a weld is inserted into the seat when a player sits on it
    if child:IsA("Weld") then -- check to see if the child that was inserted is a weld
        local character = child.Part1.Parent
        --local player = game.Players:GetPlayerFromCharacter(character)
        local cameraScript = game.Lighting.LocalScript:Clone()
        cameraScript.Parent = character -- insert the localscript into the character so it runs locally
        seat.ChildRemoved:wait() -- weld is removed when player stands up
        cameraScript.Disabled = true -- run script again
        cameraScript.Disabled = false
        cameraScript:Destroy()
    end
end)

Tested and it works. This code will set a players CameraSubject to a part named "Focus" in Workspace.Vehicle when they sit on the seat (Workspace.Seat) and when they stand up the CameraSubject will be reset (to the player's humanoid.)

0
Cheers man, works a treat! skunk940 10 — 10y
Ad

Answer this question