Im making a top down angled camera, like in retail tycoon 2. I havent came far yet, but ive got a issue that ive been stuck on for hours now, and i cant seem to figure out whats going wrong. The camera starts to shake once the player tries to move it.
-- Code is ran every frame in a bindtorenderstep with Camera priority
local CameraLocalCFrame = Plot.WorldPivot:ToObjectSpace(Camera.CFrame)
-- Handle Inputs
if UIS:IsKeyDown(Enum.KeyCode.W) then
CameraVelocity = Camera.CFrame.LookVector
end
-- Handle Camera
local NewCameraLocalPosition = CameraLocalCFrame.Position+CameraVelocity
local NewCameraLocalRotation = Vector3.new(CameraLocalCFrame:ToEulerAnglesYXZ())+CameraAngularVelocity
CameraVelocity = CameraVelocity*0.9
CameraAngularVelocity = CameraAngularVelocity*0.9
print(CameraVelocity)
local CameraWorldCFrame = (CFrame.new(NewCameraLocalPosition.X, 20, NewCameraLocalPosition.Z)):ToWorldSpace(Plot.WorldPivot) --*CFrame.Angles(NewCameraLocalRotation.X, NewCameraLocalRotation.Y, math.rad(-30))
Camera.CFrame = CameraWorldCFrame
In the video i pressed W for like 0.5 seconds, then stopped and did nothing. As soon as i stopped holding, the velocity started going down to 0,0,0. And it still continued shaking even after reaching 0,0,0.
Another issue is that the camera doesnt go that far forward for some reason. And i got no idea why that is happening.
Im suspecting both of these issues are due to the ToObjectSpace operations im doing. But i dont know how to fix it, i still want to use object space when dealing with the camera.
By “connected to a player” i assume you mean if the camera is set to scriptable or not. The camera is set to scriptable.
I don’t really understand what you mean, but i can explain what im doing in more detail.
The camera is movable using your keyboard, i only got W as a key rn when testing.
And im using object space to make it easier to position the camera relative to the players plot. So if NewCameraLocalPosition is 0,20,0, then the camera would be 20 studs above the plot.
CameraVelocity is a way for me to easily set the velocity of the camera, so if its 2,0,0 then every frame the camera would move 2 studs on the x axis
try checking if the cameratype is scriptable inside the renderstep
sometimes, people set the cameratype too early and then it gets overwritten by the default camera script loading and changing it again