Hello, I am working on a vehicle spawner that displays a vehicle in a ViewportFrame
and rotates a ViewportCamera
around the vehicle to display all sides. The code does not have any errors, yet performs the action below. Would appreciate any help!
Expected behavior:
The vehicle spins 360 degrees continuously while maintaining a fixed Y
position.
Current behavior:
https://i.gyazo.com/7defd3bd395960daf75ecc59ae3fea84.mp4
Code:
connection = RunService.RenderStepped:Connect(function()
if buttonCurrent ~= currentButton then
connection:Disconnect()
end
local currentTime = tick()
local angle = currentTime * 1
local radius = 10
local offsetX = radius * math.sin(angle)
local offsetY = radius * math.cos(angle)
local targetPosition = primaryPart.Position
local cameraPosition = targetPosition + Vector3.new(offsetX, offsetY, radius)
viewportCamera.CFrame = CFrame.lookAt(cameraPosition, targetPosition)
end)