I want to get the camera to be static on the Y axis, so that it doesn’t rotate along with the car when going uphill.
For referrence, I am trying to replicate the camera in the game “Need for speed: Undercover” (link)
I tried forcing the rotation and position part that the camera was focused on, still did not work however.
Note: The camera script is fully local and is named “FollowCamV1” in the rbxm file.
porsche.rbxm (600.0 KB)
--Service vars
local RunService = game:GetService("RunService")
local UIS = game:GetService("UserInputService")
local Mouse = game:GetService("Players").LocalPlayer:GetMouse()
--Misc vars
local heldDown = false
local isReverse = false
local Key: Enum.KeyCode = Enum.KeyCode.S
--Car vars
local Car = script.Parent.Car.Value
local DriveSeat = Car.DriveSeat
local val=script.Parent.Values
--Camera vars
local Camera = workspace.CurrentCamera
local CameraFront = Car.Body.Front
local CameraRear = Car.Body.Rear
local CameraObj = Car.Body.Obj
local CameraRot = Car.Body.Rot
--Camera angle vars
local function front()
Camera.CameraType = Enum.CameraType.Follow
Camera.CameraSubject = CameraFront
Camera.CFrame = CFrame.lookAt(Camera.CFrame.Position, CameraObj.CFrame.Position) * CFrame.Angles(math.rad(-1),math.rad(0),math.rad(0))
end
local function rear()
Camera.CameraType = Enum.CameraType.Follow
Camera.CameraSubject = CameraRear
Camera.CFrame = CFrame.lookAt(Camera.CFrame.Position, CameraFront.CFrame.Position)
end
--Camera free rotate functions
Mouse.Button2Down:Connect(function()
heldDown = true
if heldDown == true then
Camera.CameraSubject = CameraRot
RunService:UnbindFromRenderStep("CamF")
if heldDown == true and isReverse == true then
RunService:UnbindFromRenderStep("CamR")
end
end
end)
Mouse.Button2Up:Connect(function()
heldDown = false
if heldDown == false then
Camera.CameraSubject = CameraFront
RunService:BindToRenderStep("CamF", Enum.RenderPriority.Camera.Value, front)
if heldDown == false and isReverse == true then
RunService:BindToRenderStep("CamR", Enum.RenderPriority.Camera.Value, rear)
end
end
end)
--Reverse Camera
UIS.InputBegan:Connect(function(Input: InputObject)
val.Gear.Changed:connect(function()
if Input.UserInputType == Enum.UserInputType.Keyboard and Input.KeyCode == Key and val.Gear.Value == -1 then
isReverse = true
if isReverse == true then
RunService:UnbindFromRenderStep("CamF")
RunService:BindToRenderStep("CamR", Enum.RenderPriority.Camera.Value, rear)
end
end
end)
end)
UIS.InputEnded:Connect(function(Input: InputObject)
val.Gear.Changed:connect(function()
if Input.UserInputType == Enum.UserInputType.Keyboard and Input.KeyCode == Key and (val.Gear.Value == 1 or val.Gear.Value == 0) then
isReverse = false
if isReverse == false then
RunService:UnbindFromRenderStep("CamR")
RunService:BindToRenderStep("CamF", Enum.RenderPriority.Camera.Value, front)
end
end
end)
end)
RunService:BindToRenderStep("CamF", Enum.RenderPriority.Camera.Value, front)
local Removed = DriveSeat.ChildRemoved:Connect(function(cam)
if cam.Name == "SeatWeld" then
RunService:UnbindFromRenderStep("CamF")
Camera.CameraType = "Custom"
end
end)
Any solutions? Thanks in advance.