I made a simple piece of code that makes the camera follow the plane using tweenservice to make the camera smoother and runservice to keep it constantly running. It causes this problem to be super choppy when the plane moves. Does anyone know how to fix this problem?
I don’t think there’s a good way to override tweens constantly without it being super messy.
Instead, I would probably use springs following your mouse movement instead, and just centering your camera on the ship.
You can find a really easy to use spring module here (made by blackshibe):
Heres a little demo I cooked up in ~30 mins.
You can find the script inside of StarterPlayerScripts CameraMovementDemo.rbxl (46.6 KB)
local RunService = game:GetService("RunService")
local SpringModule = require(script.spring)
local CameraSpring = SpringModule.create()
local Camera = workspace.CurrentCamera
local Mouse = game.Players.LocalPlayer:GetMouse()
local Part = workspace.Part1
local CameraDistanceFromPart = 5
Camera.CameraType = Enum.CameraType.Scriptable
Camera.CameraSubject = Part
Camera.CFrame = CFrame.lookAt(Vector3.new(0,3,0), Part.Position)
RunService.RenderStepped:Connect(function (dt)
local PartLookVector = Part.CFrame.LookVector
Camera.CFrame = CFrame.lookAt(Part.Position - (PartLookVector * CameraDistanceFromPart), Part.Position)
local ScreenHalfX = Mouse.ViewSizeX/2
local ScreenHalfY = Mouse.ViewSizeY/2
local MouseXRelative = Mouse.X - ScreenHalfX
local MouseYRelative = Mouse.Y - ScreenHalfY
CameraSpring:shove(Vector3.new(MouseXRelative/10000, MouseYRelative/10000, 0))
CameraSpring:update(dt)
Camera.CFrame = Camera.CFrame * CFrame.Angles(-CameraSpring.Position.Y, -CameraSpring.Position.X, 0)
end)
Hi, thank you so much for the module and the demo script - it works amazingly well. But, the problem continues as the camera is still pretty choppy, not as worse as tweening the camera CFrame.
I fix this by using velocity + cframe instead of just adding a tween cframe and I created a part for camera to facing to that part and You need to add Vector3Value for tween. (But you can modify this for not using target part)
This is just example CamPo is Vector3Value
--Make Tween of Vector3Value like
--{
-- Value = BodyOfVehicle.Velocity / DragToCenter
--}
local CalPo = StaticCamPosition - (CamPo.Value)
lcoal CalCFrame = CFrame.lookAt(CalPo,CamTarget.Position)
camera.CFrame = CalCFrame
P.S. Sorry I’m not good at eng XD, Your game is so cool!
The choppiness you’re experiencing with the camera movement can be improved by making a few changes to your code. Here are some suggestions:
Use a variable to track the Tween in progress:
Declare a variable outside the RenderStepped function to store the active Tween.
Check if the Tween is already running before creating a new one.
If the Tween is already running, do not create a new Tween.
Remove unnecessary variables:
You don’t need to store the RenderStepped connection in a variable (camrs). You can directly connect the function call.
Adjust the timing of the Tween:
Experiment with different TweenInfo values to find the smoothest camera movement for your specific case. You can adjust the duration (0.1 in your code) and the easing style to achieve the desired effect.
Here’s an updated version of your code with these improvements:
local planemodel = script.Parent.PlaneModel.Value
local cam = game.Workspace.CurrentCamera
local activeTween = nil
game:GetService("RunService").RenderStepped:Connect(function()
local cf = planemodel.Important.Parts.Engine.CFrame * CFrame.new(0, 20, 60)
if not activeTween or activeTween:IsCompleted() then
activeTween = game:GetService("TweenService"):Create(cam, TweenInfo.new(0.2, Enum.EasingStyle.Sine, Enum.EasingDirection.InOut), {
CFrame = cf
})
activeTween:Play()
end
end)
Feel free to adjust the duration and the easing style in the TweenInfo parameters to achieve the desired smoothness for your camera movement. Additionally, make sure the planemodel variable correctly references the plane model in your scene.
Remember to place this code in a LocalScript within a location where it can run, such as StarterPlayerScripts.
Actually, as I was making edits the choppiness stopped becoming an issue using this script. One more thing, is it possible for me to lock the camera relative to the engine so the camera moves as it rolls/rotates?