I’ve encountered an issue with the rover’s camera. The camera isn’t behaving as expected; instead of smoothly following the rover or providing a dynamic view, it remains fixed in one position. This lack of stability prevents it from adapting to the rover’s movements or changing perspective, which affects the overall gameplay experience. How can I fix this issue so that the camera functions correctly and follows the rover as intended?
local rs = game:GetService("ReplicatedStorage")
local remotes = rs.Remotes
local remote = remotes:WaitForChild("RemoteEvent")
local part = workspace["Rover One"].CameraB.BaseCamera
local currentMousePos
remote.OnServerEvent:Connect(function(player, mousePos)
currentMousePos = mousePos
end)
while task.wait() do
if part and currentMousePos then
local partPos = part.Position
local screenPoint = workspace.CurrentCamera:ScreenPointToRay(currentMousePos.X, currentMousePos.Y)
local direction = screenPoint.Direction
local distance = (partPos - screenPoint.Origin).magnitude
local targetPosition = screenPoint.Origin + direction * distance
local targetCFrame = CFrame.lookAt(partPos, targetPosition)
local currentCFrame = part.CFrame
part.CFrame = currentCFrame:Lerp(targetCFrame, 0.1)
end
end
Client:
local player = game.Players.LocalPlayer
local getMouse = player:GetMouse()
local rs = game:GetService("ReplicatedStorage")
local remotes = rs.Remotes
local remote = remotes:WaitForChild("RemoteEvent")
getMouse.Move:Connect(function()
local mousePos = getMouse.Hit.Position
remote:FireServer(mousePos)
end)
I searched on YouTube but couldn’t find a solution. I’m hoping this developer hub can help me resolve the issue.
The problem is that it is being updated using the Server Position property and not the client in which it has network ownership. (Server lags behind client)
Visualization:
Better to use hinge constraints if going for a complete physics based solutions, or welds for pure CFrames.
Or perhaps you can use .Stepped:Wait() to let the vehicle turret position update first?
I rewatched the video and I don’t think it’s what the other guy said. The camera isn’t lagging behind, something is wrong with the way you’re calculating the CFrame
You’re using CFrame:Lerp() but you’re always setting the alpha (2nd argument) to 0.1, I think that’s why it’s not positioned correctly. Try setting it to 1 and see what happens.
Welding it doesn’t allow the camera to move with the mouse pointer. I’ve already tried it. Additionally, it causes the rest of the rover, including the camera, to fling out.
Okay so the reason the position isn’t changing is because you’re setting it to the same position. You need a part that’s moving with the Rover, you can copy the BaseCamera make it invisible and weld it to the Rover, then set the BaseCamera to the welded parts position.