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: Uh... making a brick float up and down?

Previous Thread :: Next Thread 
AbstractMadness is not online. AbstractMadness
Joined: 22 Dec 2014
Total Posts: 20425
28 Mar 2015 09:21 PM
I'm trying to make pets like taymaster's and this is giving me an error.

local pet = script.Parent
local owner = pet.Parent
local maximum = 8
local minimum = -3

while wait() do
if ((owner.Torso.CFrame * CFrame.new(0,maximum,0)) > pet.CFrame) then
pet.CFrame = owner.Torso.CFrame * CFrame.new(0,-.1,0)
elseif ((owner.Torso.CFrame * CFrame.new(0,minimum,0)) < pet.CFrame) then
pet.CFrame = owner.Torso.CFrame * CFrame.new(0,.1,0)
end
end

Output Error:

21:20:06.654 - Workspace.Player.PET1.PETSCRIPT:7: attempt to compare two userdata values
21:20:06.655 - Stack Begin
21:20:06.656 - Script 'Workspace.Player.PET1.PETSCRIPT', Line 7
21:20:06.658 - Stack End
Report Abuse
AbstractMadness is not online. AbstractMadness
Joined: 22 Dec 2014
Total Posts: 20425
28 Mar 2015 09:27 PM
Okay I got it to work without throwing errors, but now it won't float up and down...

local pet = script.Parent
local owner = pet.Parent
local maximum = 8
local minimum = -3

while wait() do
if ((owner.Torso.CFrame.Y + maximum) > pet.CFrame.Y) then
pet.CFrame = owner.Torso.CFrame * CFrame.new(4,-.1,0)
elseif ((owner.Torso.CFrame.Y + minimum) < pet.CFrame.Y) then
pet.CFrame = owner.Torso.CFrame * CFrame.new(4,.1,0)
else
pet.CFrame = owner.Torso.CFrame * CFrame.new(4,.1,0)
end
end
Report Abuse
JimmyChance is not online. JimmyChance
Joined: 01 Nov 2009
Total Posts: 3681
28 Mar 2015 09:28 PM
local startOffset = Vector3.new(0, 2.5, 5)
local increment = 5

for step = 0, math.huge, increment do
wait()
pet.CFrame = owner.Torso.CFrame * CFrame.new(0, startOffset.Y + math.sin(math.rad(step)), startOffset.Z)
end
Report Abuse
LegendaryAccount is not online. LegendaryAccount
Joined: 02 Jun 2010
Total Posts: 13193
28 Mar 2015 09:29 PM
I believe his pets use position object and non collide
Report Abuse
AbstractMadness is not online. AbstractMadness
Joined: 22 Dec 2014
Total Posts: 20425
28 Mar 2015 09:29 PM
wat?
Report Abuse
LegendaryAccount is not online. LegendaryAccount
Joined: 02 Jun 2010
Total Posts: 13193
28 Mar 2015 09:30 PM
Oh taymaster I was thinking of ripull
Report Abuse
AbstractMadness is not online. AbstractMadness
Joined: 22 Dec 2014
Total Posts: 20425
28 Mar 2015 09:32 PM
ye. Well, his code worked even though I didn't understand it. Thanks!
Report Abuse
JimmyChance is not online. JimmyChance
Joined: 01 Nov 2009
Total Posts: 3681
28 Mar 2015 09:33 PM
In the code I posted, you can use any kind of sine wave (I just use sine for any repetitive oscillation though).
Report Abuse
AbstractMadness is not online. AbstractMadness
Joined: 22 Dec 2014
Total Posts: 20425
28 Mar 2015 09:33 PM
i'm only in algebra 1 help me i don't understand
Report Abuse
JimmyChance is not online. JimmyChance
Joined: 01 Nov 2009
Total Posts: 3681
28 Mar 2015 09:34 PM
You mean making the code or the explanation of it?
Report Abuse
AbstractMadness is not online. AbstractMadness
Joined: 22 Dec 2014
Total Posts: 20425
28 Mar 2015 09:35 PM
everything
Report Abuse
JimmyChance is not online. JimmyChance
Joined: 01 Nov 2009
Total Posts: 3681
28 Mar 2015 09:54 PM
I only took Geometry in 24 days one summer so I can't explain trigonometric functions well enough, maybe not even at all (big mistake). But as for the code:

What you want to do is use a function for oscillation (like sine waves as I mentioned), and input any given period as its domain (or all real numbers because sine waves are repetitive) so that you can use its result (which is a value between -1 and 1 in this case) for the Y.

For instance, if we were going to make a floating brick in workspace over a period of 0 and 2 pi (a basic up and down motion), all we have to do is plug in the X value (I will use a numeric for loop).

for x = 0, 1, 1/30
wait()
Part.CFrame = CFrame.new(0, x * (2 * math.pi), 0)
end

This will make a part go up and down once in a second, but we can make it repetitive:

for x = 0, math.huge, 1/30
wait()
Part.CFrame = CFrame.new(0, x * (2 * math.pi), 0)
end

Since the domain is infinite, we can just simplify it without interpolating the period.

for x = 0, math.huge
wait()
Part.CFrame = CFrame.new(0, math.rad(x), 0)
end
Report Abuse
JimmyChance is not online. JimmyChance
Joined: 01 Nov 2009
Total Posts: 3681
28 Mar 2015 09:56 PM
Or ask someone like DrMathematica to explain it for you (since I'm terrible).
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