What do you want to achieve? While seated offset the camera left or right when looking back.
What is the issue? The game will be in first person only and right now, when you are trying to reverse a vehicle you cant see anything, seat just blocks the view.
I tried raycasting but yeah, realized its not an option because every time it casts a ray at a seat it keeps hitting and missing so the camera goes crazy
local player = game.Players.LocalPlayer
local char = player.Character
local RunService = game:GetService("RunService")
RunService.RenderStepped:Connect(function(step)
local ray = Ray.new(workspace.CurrentCamera.CFrame.Position, workspace.CurrentCamera.CFrame.LookVector*2)
local ignoreList = char:GetChildren()
local hit, pos = game.Workspace:FindPartOnRayWithIgnoreList(ray, ignoreList)
if hit then
char.Humanoid.CameraOffset = Vector3.new(-3, 0, 0)
else
char.Humanoid.CameraOffset = Vector3.new(0, 0, 0)
end
end)
I would recommend a custom camera script for this, but I’ve made this and it works. This won’t work correctly in third person, but you said the game is first person only. This uses the dot product of the camera look and character look vectors. Basically, how close are the two vectors to each other (from -1 to 1).
Here is the code:
local runService = game:GetService("RunService")
local finalOffset = Vector3.new(-3, 0, 0)
local cam = workspace.CurrentCamera
local primaryPart = script.Parent:WaitForChild("HumanoidRootPart")
local humanoid = script.Parent:WaitForChild("Humanoid")
runService.RenderStepped:Connect(function(step)
humanoid.CameraOffset = finalOffset * math.min(0, cam.CFrame.LookVector:Dot(primaryPart.CFrame.LookVector))
end)
This absolutely gets the job done! I’ll still fiddle around with it and see if I can get it to lean on the other side too, but Thank you so much for helping me out and sharing this gem!