Ad
Still have questions? Join our Discord server and get real time help.
Log in to vote
3

How to properly use magnitude?

Asked by
Shawnyg 4241 Trusted Badge of Merit Snack Break Moderation Voter Administrator Community Moderator Super Administrator
6 years ago

This script is supposed to increase if you get farther away from the brick, ad decrease as you approach it. Just so you can see it wherever you go. My problem is that it keeps increasing and decreasing randomly. Tips?

local Sizing = coroutine.wrap(function()
    pl = game.Players.LocalPlayer
    c = game.Workspace.CurrentCamera
    s = c.Part
    f = s.Rank.Frame
    old = 0
    while true do
        wait()
        if (old < (pl.Character.Head.Position - s.Position).magnitude) then
            f.Size = f.Size - UDim2.new(.1,0,.1,0)
            old = (pl.Character.Head.Position - s.Position).magnitude
            wait()
        elseif (old > (pl.Character.Head.Position - s.Position).magnitude) then
            wait()
            f.Size = f.Size + UDim2.new(.1,0,.1,0)
            old = (pl.Character.Head.Position - s.Position).magnitude
        elseif (old == (pl.Character.Head.Position - s.Position).magnitude) then
            wait()
        end
    end
end)
        game.Lighting.Part:clone().Parent = game.Workspace.CurrentCamera
        Sizing()

1 answer

Log in to vote
6
Answered by
BlueTaslem 17922 Moderation Voter Administrator Community Moderator Super Administrator
6 years ago

This is a problem since moving close and far by different rates all change the size at the same rate.

You should instead have a function for size in terms of distance (this will also simplify your script):

Something like this:

local dist = (pl.Character.Head.Position - s.Position).magnitude);
f.Size = UDim2.new( (4 + dist) * .01 , 0 , (4 + dist) * .01    );

Which should approximate undoing perspective sizing (although there should probably be a cap on size using math.min)


Your question wasn't described too well, so I'm not sure if I've got it right. Please let me know if this isn't what you were looking for.

1
Thanks a lot. +1'd and Accepted. Shawnyg 4241 — 6y
Ad

Answer this question