|
| 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 |
|
|
|
| 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 |
|
|
|
| 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 |
|
|
|
| 28 Mar 2015 09:29 PM |
| I believe his pets use position object and non collide |
|
|
| Report Abuse |
|
|
| |
|
|
| 28 Mar 2015 09:30 PM |
| Oh taymaster I was thinking of ripull |
|
|
| Report Abuse |
|
|
|
| 28 Mar 2015 09:32 PM |
| ye. Well, his code worked even though I didn't understand it. Thanks! |
|
|
| Report Abuse |
|
|
|
| 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 |
|
|
|
| 28 Mar 2015 09:33 PM |
| i'm only in algebra 1 help me i don't understand |
|
|
| Report Abuse |
|
|
|
| 28 Mar 2015 09:34 PM |
| You mean making the code or the explanation of it? |
|
|
| Report Abuse |
|
|
| |
|
|
| 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 |
|
|
|
| 28 Mar 2015 09:56 PM |
| Or ask someone like DrMathematica to explain it for you (since I'm terrible). |
|
|
| Report Abuse |
|
|