Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

How do I make an orb float up and down and increase and decrease in size?

Asked by 8 years ago

Hi,

I want to make an orb float un and down in the air; and also increase and decrease in size. Here is the script that I attempted to use.

Floating Script

local orb = script.Parent
local orbposition = script.Parent.Position.Y

while 0==0 do
    while orbposition <= 10040 do
        orbposition = orbposition + .1
        wait(.1)
    end
    while orbposition >= 10026 do
        orbposition = orbposition - .1
        wait(.1)
    end
end

And I have no idea how to make the orb increase and decrease in size. :-(

Thank you so much for reading and helping me out with my dilemma.

Sincerely, BloodySoldier2002

1 answer

Log in to vote
1
Answered by 8 years ago
-- Configure Movement
local orbIterations = 50 -- The amount of steps it will take
local orbStepSize = 0.1  -- The size of each step
local orbStepTime = 0.1  -- The time between each step

-- Used internally
local orb = script.Parent
local orbYMax = orb.Position.Y + (orbIterations * orbStepSize)  -- The maximum point it will reach
local orbYMin = orb.Position.Y - (orbIterations *orbStepSize)   -- The minimum point it will reach
local direction = 1                                             -- 1 = up and -1 = down

repeat
    -- When setting position, X,Y,Z are protected variables and cannot be directly accessed
    -- So you must create a new vector and assign it to the position of the part.
    orb.Position = Vector3.new(orb.Position.X, orb.Position.Y + (direction * orbStepSize), orb.Position.Z)
    if(orb.Position.Y <= orbYMin) then
        direction = 1
    elseif(orb.Position.Y >= orbYMax) then
        direction = -1
    end
    wait(orbStepTime)
until(false)

The above is a working and commented implementation of what you have, with configurable variables so you can understand more of the process. As for the size, I have commented inside on how to manipulate Vectors, size is a similiar theory but it should be documented quite well on the wiki.

0
Thank you so much! BloodySoldier2002 10 — 8y
Ad

Answer this question