ZizZazZuz
|
  |
| Joined: 16 Jun 2008 |
| Total Posts: 2743 |
|
|
| 24 Feb 2012 08:08 PM |
I want a random number of parts between 4 and 6 to stretch between two parts. The target is named Target. The following script goes in the origin part.
math.randomseed(tick()) endPnt = game.Workspace.Target interPnt = math.random(4, 6)
for i = 1, interPnt do
print("Test: lerpD Result is ".. 1/(i/interPnt)) print("Test: endPnt Result is ".. endPnt.Position.x ..", ".. endPnt.Position.y ..", ".. endPnt.Position.z) curPnt = script.Parent.Position:lerp(endPnt.Position, 1/(i/interPnt)) print("Test: curPos is now ".. curPnt.x ..", ".. curPnt.y ..", ".. curPnt.z) curPnt = curPnt-- + Vector3.new(math.random(-2, 2), math.random(-2, 2), math.random(-2, 2)) if prevPnt == nil then p = Instance.new("Part") p.Transparency = 0.3 p.Size = Vector3.new(1, 1, (script.Parent.Position - curPnt).magnitude) p.Anchored = true p.Parent = workspace p.CFrame = CFrame.new(script.Parent.CFrame.p, curPnt) * CFrame.new(0, 0, (script.Parent.Position - curPnt).magnitude) else p = Instance.new("Part") p.Transparency = 0.3 p.Size = Vector3.new(1, 1, (prevPnt - curPnt).magnitude) p.Anchored = true p.Parent = workspace p.CFrame = CFrame.new(prevPnt, curPnt) * CFrame.new(0, 0, (prevPnt - curPnt).magnitude) end prevPnt = curPnt end
Why does it behave so erratically? |
|
|
| Report Abuse |
|
|
ZizZazZuz
|
  |
| Joined: 16 Jun 2008 |
| Total Posts: 2743 |
|
|
| 24 Feb 2012 08:16 PM |
| Where is @stravant when I need him? |
|
|
| Report Abuse |
|
|
|
| 24 Feb 2012 08:18 PM |
| what about @blueymaddog? :D? |
|
|
| Report Abuse |
|
|
ZizZazZuz
|
  |
| Joined: 16 Jun 2008 |
| Total Posts: 2743 |
|
| |
|
stravant
|
  |
 |
| Joined: 22 Oct 2007 |
| Total Posts: 2893 |
|
|
| 24 Feb 2012 08:42 PM |
I can only type so fast!
There's a lot of minor errors there (One of the easiest ones to point out is that you translated each link a full magnitude of the length of the link, when you really wanted to translate it only 1/2 of a magnitude). You have the right idea for everything but it's still very rough around the edges.
Rather than show you how to do it, I have almost an exact copy of what you're trying to write that I did for one of the gears that I made. Do you know about the Lazer-Vision shades? Just get a copy of those off of free models and look at how they work. |
|
|
| Report Abuse |
|
|
ZizZazZuz
|
  |
| Joined: 16 Jun 2008 |
| Total Posts: 2743 |
|
|
| 24 Feb 2012 08:52 PM |
| Could you maybe post a link to one of them? Having trouble finding one. |
|
|
| Report Abuse |
|
|
stravant
|
  |
 |
| Joined: 22 Oct 2007 |
| Total Posts: 2893 |
|
|
| 24 Feb 2012 09:06 PM |
This one: http://www.roblox.com/Laservision-Shades-G3-item?id=69499452
Sorry, should have given a link in the first place. |
|
|
| Report Abuse |
|
|
ZizZazZuz
|
  |
| Joined: 16 Jun 2008 |
| Total Posts: 2743 |
|
|
| 24 Feb 2012 09:11 PM |
| OK man, I'm sorry, but I have NO idea what I am looking for in that sea of code. |
|
|
| Report Abuse |
|
|
stravant
|
  |
 |
| Joined: 22 Oct 2007 |
| Total Posts: 2893 |
|
|
| 24 Feb 2012 09:24 PM |
This is the only relevant bit. I should just have posted that.
The show function does what your code is trying to do. Shows a segmented beam from one point to another:
http://codepad.org/gC7HpI6k |
|
|
| Report Abuse |
|
|
ZizZazZuz
|
  |
| Joined: 16 Jun 2008 |
| Total Posts: 2743 |
|
|
| 25 Feb 2012 02:55 PM |
Ima go through this one block at a time. What does this do?
class'WavyBeam'(function(this, numSegs) --What is class? local mSegList = {} for i = 1, numSegs do mSegList[i] = Create'Part'{ Name = 'SpotWeld_BeamBit', Anchored = true, CanCollide = false, FormFactor = 'Custom', BrickColor = BeamColor, Transparency = 0.3, } RaycastIgnore:addIgnore(mSegList[i]) --??? |
|
|
| Report Abuse |
|
|
stravant
|
  |
 |
| Joined: 22 Oct 2007 |
| Total Posts: 2893 |
|
|
| 25 Feb 2012 03:01 PM |
Well, most of the code is pretty abstract stuff, and it would take a long time to explain it to a beginner, just ignore the lines that don't make any sense out of context.
Basically, 'class' is a function that I invented to let me easily declare types of object like the built-in Roblox ones, in order to make my code more readable when it gets to be like... 2000 lines long.
RaycastIgnore is one of those classes that I made, in order to maintain a list of all of the line segments and stuff that I created that should be ignored when I'm trying to find what you're shooting at. |
|
|
| Report Abuse |
|
|
C0D3Y
|
  |
| Joined: 24 Jul 2010 |
| Total Posts: 1692 |
|
|
| 25 Feb 2012 03:03 PM |
| Ziz, here's the main problem I see. If you are using generic for statements, you need to put a # before the name of the table. So it'd be i = 1, #numSegs |
|
|
| Report Abuse |
|
|
stravant
|
  |
 |
| Joined: 22 Oct 2007 |
| Total Posts: 2893 |
|
|
| 25 Feb 2012 03:09 PM |
One, that's not a generic for statement, it's a numeric for. A generic for looks like this: `for a, b, ... etc in iter_func( object ) do`
Two, it's entirely correct, because he isn't iterating over a table, interPnt is just a number. |
|
|
| Report Abuse |
|
|
SDuke524
|
  |
| Joined: 29 Jul 2008 |
| Total Posts: 6267 |
|
|
| 25 Feb 2012 03:42 PM |
math.randomseed(tick()) startPnt=script.Parent; endPnt = game.Workspace.Target interPnt = math.random(4, 6) for i = 1, interPnt do local p=Instance.new("Part",workspace); p.Transparency=0.3; p.Size=Vector3.new(2,1,1);--you shouldn't set them all to the magnitude p.Anchored=true; p.CFrame=CFrame.new( startPnt:Lerp(endPnt,(1/interPnt)*i),--interval*iteration endPnt ); end |
|
|
| Report Abuse |
|
|
stravant
|
  |
 |
| Joined: 22 Oct 2007 |
| Total Posts: 2893 |
|
|
| 25 Feb 2012 03:44 PM |
| I imagine he wants to make it a long thin connected line, in which case he does need it to use magnitude in those places. |
|
|
| Report Abuse |
|
|
SDuke524
|
  |
| Joined: 29 Jul 2008 |
| Total Posts: 6267 |
|
|
| 25 Feb 2012 03:46 PM |
| p.Size=Vector3.new(1,1,(endPnt-startPnt).magnitude/interPnt); |
|
|
| Report Abuse |
|
|
stravant
|
  |
 |
| Joined: 22 Oct 2007 |
| Total Posts: 2893 |
|
|
| 25 Feb 2012 03:54 PM |
| And that would only work until he adds a random offset to each point back. |
|
|
| Report Abuse |
|
|
SDuke524
|
  |
| Joined: 29 Jul 2008 |
| Total Posts: 6267 |
|
|
| 25 Feb 2012 03:58 PM |
Fine then
http://www.roblox.com/fractaled-laser-item?id=59364462 |
|
|
| Report Abuse |
|
|
ZizZazZuz
|
  |
| Joined: 16 Jun 2008 |
| Total Posts: 2743 |
|
|
| 26 Feb 2012 08:59 PM |
| I fixed it for myself, started completely over. |
|
|
| Report Abuse |
|
|