#Part resizing relative to camera

4 messages · Page 1 of 1 (latest)

deft canyon
#

Im trying to create a script that dynamically adjusts the size of a part based on the player's camera distance, making it appear as if the part maintains a constant size relative to the player. The part should grow larger as the player moves away and shrink as the player gets closer.

local part = game.Workspace.Part 
local player = game.Players.LocalPlayer
local camera = workspace.CurrentCamera

local function updateSize()
    local distance = (part.Position - camera.CFrame.Position).Magnitude
    local scaleFactor = math.clamp(1 - distance / 50, 0.5, 1.5) -- Adjust these values as needed

    part.Size = Vector3.new(10 * scaleFactor, 5 * scaleFactor, 3) -- Adjust the initial size as needed
end

-- Connect the updateSize function to the RenderStepped event to update continuously
game:GetService("RunService").RenderStepped:Connect(updateSize)

-- Run the updateSize function initially
updateSize()

I cant come across any tutorials, bit confused

marsh spoke
#

Have you tried distance/size?

deft canyon
#

using my code right? or do I need to remake