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 » Scripting Helpers
Home Search
 

Re: Line of parts

Previous Thread :: Next Thread 
ZizZazZuz is not online. 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 is not online. ZizZazZuz
Joined: 16 Jun 2008
Total Posts: 2743
24 Feb 2012 08:16 PM
Where is @stravant when I need him?
Report Abuse
blueymaddog is not online. blueymaddog
Joined: 23 Sep 2009
Total Posts: 5459
24 Feb 2012 08:18 PM
what about @blueymaddog? :D?
Report Abuse
ZizZazZuz is not online. ZizZazZuz
Joined: 16 Jun 2008
Total Posts: 2743
24 Feb 2012 08:38 PM
Hurry oop.
Report Abuse
stravant is not online. stravant
Forum Moderator
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 is not online. 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 is not online. stravant
Forum Moderator
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 is not online. 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 is not online. stravant
Forum Moderator
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 is not online. 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 is not online. stravant
Forum Moderator
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 is not online. 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 is not online. stravant
Forum Moderator
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 is not online. 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 is not online. stravant
Forum Moderator
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 is not online. 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 is not online. stravant
Forum Moderator
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 is not online. 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 is not online. ZizZazZuz
Joined: 16 Jun 2008
Total Posts: 2743
26 Feb 2012 08:59 PM
I fixed it for myself, started completely over.
Report Abuse
Previous Thread :: Next Thread 
Page 1 of 1
 
 
ROBLOX Forum » Game Creation and Development » Scripting Helpers
   
 
   
  • 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