generic image
Processing...
  • Games
  • Catalog
  • Develop
  • Robux
  • Search in Players
  • Search in Games
  • Search in Catalog
  • Search in Groups
  • Search in Library
  • Log In
  • Sign Up
  • Games
  • Catalog
  • Develop
  • Robux
   
ROBLOX Forum » Game Creation and Development » Scripters
Home Search
 

Re: Stumped by a (relatively) simple script! :(

Previous Thread :: Next Thread 
Thundergod500 is not online. Thundergod500
Joined: 10 Jul 2008
Total Posts: 70
23 Feb 2016 05:13 PM
So, I've been racking my brain trying to figure out a compact and clean solution to my problem. I want to make a brick float up and down, and make it look like it's got some sort of momentum to it. I'm able to make it work, but I end up using like 12 different functions, and I'd rather just do it with a math equation of some kind. I'm very new to scripting, and any help would be incredibly useful

var=0
vertical=.01
x=10
--MATH FUNCTIONS
function math1()
var=var+1
end

function math2()
var=var-1
end

--UP FUNCTIONS

function up()
script.Parent.CFrame = script.Parent.CFrame * CFrame.new (0,vertical,0)
end

function down()
script.Parent.CFrame = script.Parent.CFrame * CFrame.new (0,-vertical,0)
end


--START OF MOVEMENT

while var==0 do

--UP
repeat
repeat
up()
math1()
wait(.01)
until var==x
x=x+10
vertical=vertical+.01
wait(.01)
print (x)
until x==100

repeat
repeat
up()
math1()
wait(.01)
until var==x

x=x+10
vertical=vertical-.01
wait(.01)
print (x)
until x==200

var=0
x=10

print (x)
--DOWN

repeat
repeat
down()
math1()
wait(.01)
until var==x
x=x+10
vertical=vertical+.01
wait(.01)
print (x)
until x==100

repeat
repeat
down()
math1()
wait(.01)
until var==x

x=x+10
vertical=vertical-.01
wait(.01)
print (x)
until x==200

var=0
x=10

end
Report Abuse
Thundergod500 is not online. Thundergod500
Joined: 10 Jul 2008
Total Posts: 70
23 Feb 2016 05:15 PM
This is the version that works, but I'd like it to be a bit more compact...

y=0
print (y)
--UP FUNCTIONS

function movement1()
script.Parent.CFrame = script.Parent.CFrame * CFrame.new (0,.1,0)

y = y + 1

wait(.01)

end

function movement2()
script.Parent.CFrame = script.Parent.CFrame * CFrame.new (0,.08,0)

y = y + 1

wait(.01)

end

function movement3()
script.Parent.CFrame = script.Parent.CFrame * CFrame.new (0,.06,0)

y = y + 1

wait(.01)

end


function movement4()
script.Parent.CFrame = script.Parent.CFrame * CFrame.new (0,.04,0)

y = y + 1

wait(.01)

end

function movement5()
script.Parent.CFrame = script.Parent.CFrame * CFrame.new (0,.02,0)

y = y + 1

wait(.01)

end

function movement6()
script.Parent.CFrame = script.Parent.CFrame * CFrame.new (0,.01,0)

y = y + 1

wait(.01)

end

--DOWN FUNCTIONS

function movement7()
script.Parent.CFrame = script.Parent.CFrame * CFrame.new (0,-.01,0)

y = y - 1

wait(.01)

end

function movement8()
script.Parent.CFrame = script.Parent.CFrame * CFrame.new (0,-.02,0)

y = y - 1

wait(.01)

end

function movement9()
script.Parent.CFrame = script.Parent.CFrame * CFrame.new (0,-.04,0)

y = y - 1

wait(.01)

end


function movement10()
script.Parent.CFrame = script.Parent.CFrame * CFrame.new (0,-.06,0)

y = y - 1

wait(.01)

end

function movement11()
script.Parent.CFrame = script.Parent.CFrame * CFrame.new (0,-.08,0)

y = y - 1

wait(.01)

end

function movement12()
script.Parent.CFrame = script.Parent.CFrame * CFrame.new (0,-.1,0)

y = y - 1

wait(.01)

end


repeat

--START OF MOVEMENT

--UP

while y==0 do

repeat
movement6()
print (y)

until y == 10

--

while y == 10 do

repeat
movement5()
print (y)

until y == 20

--

while y == 20 do

repeat
movement4()
print (y)

until y == 30

--

while y == 30 do

repeat
movement3()
print (y)

until y == 40

--

while y == 40 do

repeat
movement2()
print (y)

until y == 50

--

while y == 50 do

repeat
movement1()
print (y)

until y == 60


--

while y == 60 do

repeat

movement2()
print (y)

until y == 70

--

while y == 70 do

repeat

movement3()
print (y)

until y == 80

--

while y == 80 do

repeat

movement4()
print (y)

until y == 90

--

while y == 90 do

repeat

movement5()
print (y)

until y == 100

--

while y == 100 do

repeat

movement6()
print (y)


until y == 110
print("Up Complete")
-- down

print (y)

while y == 110 do

repeat
movement7()
print (y)

until y == 100

--

while y == 100 do

repeat
movement8()
print (y)

until y == 90
--

while y == 90 do

repeat
movement9()
print (y)

until y == 80

--

while y == 80 do

repeat
movement10()
print (y)

until y == 70

--

while y == 70 do

repeat
movement11()
print (y)

until y == 60

--

while y == 60 do

repeat
movement12()
print (y)

until y == 50

--

while y == 50 do

repeat
movement11()
print (y)

until y == 40

--

while y == 40 do

repeat
movement10()
print (y)

until y == 30

--

while y == 30 do

repeat
movement9()
print (y)

until y == 20

--

while y == 20 do

repeat
movement8()
print (y)

until y == 10

--

while y == 10 do

repeat
movement7()
print (y)

until y == 0
print("Down Complete")
--
print (y)



end

end

end

end

end

end

end

end

end

end

end

end

end

end

end

end

end

end

end

end

end

end
wait(.1)

until y==1000

print("ended")
Report Abuse
Thundergod500 is not online. Thundergod500
Joined: 10 Jul 2008
Total Posts: 70
23 Feb 2016 07:01 PM
bumpy bump- Still looking for help
Report Abuse
SwagCuzYolo is not online. SwagCuzYolo
Joined: 31 Oct 2013
Total Posts: 1224
23 Feb 2016 07:12 PM
are you dumb
Report Abuse
Thundergod500 is not online. Thundergod500
Joined: 10 Jul 2008
Total Posts: 70
23 Feb 2016 07:41 PM
As I said, I'm new to scripting. So in a way yes.
Report Abuse
malachi11 is not online. malachi11
Joined: 07 May 2008
Total Posts: 2420
23 Feb 2016 08:00 PM
If you're doing what I think you're doing... math.sin should work.


num=0
while true do
part.CFrame=CFrame.new(x,y+math.sin(num),z) -- Substitute x, y and z for values.
num=num+0.1 --Change this 0.1 to something larger or smaller if necessary.
end
Report Abuse
Thundergod500 is not online. Thundergod500
Joined: 10 Jul 2008
Total Posts: 70
23 Feb 2016 08:14 PM
Thank you so much. I had no idea there was something built in for sine waves
Report Abuse
Previous Thread :: Next Thread 
Page 1 of 1
 
 
ROBLOX Forum » Game Creation and Development » Scripters
   
 
   
  • About Us
  • Jobs
  • Blog
  • Parents
  • Help
  • Terms
  • Privacy

©2017 Roblox Corporation. Roblox, the Roblox logo, Robux, Bloxy, and Powering Imagination are among our registered and unregistered trademarks in the U.S. and other countries.



Progress
Starting Roblox...
Connecting to Players...
R R

Roblox is now loading. Get ready to play!

R R

You're moments away from getting into the game!

Click here for help

Check Remember my choice and click Launch Application in the dialog box above to join games faster in the future!

Gameplay sponsored by:
Loading 0% - Starting game...
Get more with Builders Club! Join Builders Club
Choose Your Avatar
I have an account
generic image