alexmach1
|
  |
| Joined: 02 May 2008 |
| Total Posts: 1977 |
|
|
| 21 Jul 2011 08:14 AM |
| lets say i have a table full of CFrame coordinates, and there was a start and a finish CFrame coordinate. the start is permanent, whereas the finish could be any of the other CFrames in the table. how would i make a new table, from start to finish, while effectively drawing a line between as few cframes as possible with as little distance? think of it like connect the dots. |
|
|
| Report Abuse |
|
|
|
| 21 Jul 2011 08:23 AM |
table = {} om = math.hude
for i = 1,#cframe do if (starcframe - cframe[i]).magnitude < om then om = (startcframe - cframe[i]).magnitude table[1] = cframe[i] end end print(table[1])--will print the closest cframe |
|
|
| Report Abuse |
|
|
alexmach1
|
  |
| Joined: 02 May 2008 |
| Total Posts: 1977 |
|
|
| 21 Jul 2011 08:50 AM |
| that method would normally work, but then it can go anywhere from there and im trying to make the shortest line possible. |
|
|
| Report Abuse |
|
|
hyper900
|
  |
| Joined: 14 May 2009 |
| Total Posts: 873 |
|
|
| 21 Jul 2011 09:05 AM |
math.randomseed(tick()) coordinates = {start={1,1,1}} mq = "" nq = "" ne = 5 for i = 1, ne do table.insert(coordnates, "r"..i={math.random(1,100),math.random(1,100),math.random(1,100)}) end repeat nm = math.random(1, #coordinates) until nm ~= 1 for q = 1, #coordinates[1] do nq = nq..q end for w = 1, #coordinates[nm] do mq = mq..w end c1 = tonumber(string.sub(nq, 1, 1)) c2 = tonumber(string.sub(nq, 2, 2)) c3 = tonumber(string.sub(nq, 3, 3)) v1 = tonumber(string.sub(mq, 1, 1)) v2 = tonumber(string.sub(mq, 2, 2)) v3 = tonumber(string.sub(mq, 3, 3)) mag = (Vector3.new(v1,v2,v3)-Vector3.new(c1,c2,c3)).magnitude print(mag)
If you're trying to do what I think you are, that should work, hopefully |
|
|
| Report Abuse |
|
|
hyper900
|
  |
| Joined: 14 May 2009 |
| Total Posts: 873 |
|
|
| 21 Jul 2011 09:07 AM |
Wait, messed up:
math.randomseed(tick()) coordinates = {start={1,1,1}} mq = "" nq = "" ne = 5 for i = 1, ne do table.insert(coordnates, "r"..i={math.random(1,100),math.random(1,100),math.random(1,100)}) end repeat nm = math.random(1, #coordinates) until nm ~= 1 for q = 1, #coordinates[1] do nq = nq..coordinates[1][q] end for w = 1, #coordinates[nm] do mq = mq..coordinates[nm][w] end c1 = tonumber(string.sub(nq, 1, 1)) c2 = tonumber(string.sub(nq, 2, 2)) c3 = tonumber(string.sub(nq, 3, 3)) v1 = tonumber(string.sub(mq, 1, 1)) v2 = tonumber(string.sub(mq, 2, 2)) v3 = tonumber(string.sub(mq, 3, 3)) mag = (Vector3.new(v1,v2,v3)-Vector3.new(c1,c2,c3)).magnitude print(mag)
that's better
|
|
|
| Report Abuse |
|
|
alexmach1
|
  |
| Joined: 02 May 2008 |
| Total Posts: 1977 |
|
|
| 21 Jul 2011 09:42 AM |
| wow roblox, i cant show the code i need help with because it contains "html" wtf |
|
|
| Report Abuse |
|
|
Ozzypig
|
  |
| Joined: 27 Mar 2008 |
| Total Posts: 4906 |
|
|
| 21 Jul 2011 09:43 AM |
Put spaces around your less than signs "<". That causes that error.
~Ozzy |
|
|
| Report Abuse |
|
|
alexmach1
|
  |
| Joined: 02 May 2008 |
| Total Posts: 1977 |
|
|
| 21 Jul 2011 10:07 AM |
function getpath(newpoints, start, finish, visual) dis=100000 points={} for i, v in pairs(newpoints)do for q, w in pairs(mypath)do if w~=v then table.insert(points, v) end end end print("1") for i, v in pairs(points)do part.CFrame=v local ray = Ray.new(start.p,(v.p-start.p).unit*500) local s,p=game.Workspace:FindPartOnRay(ray,tool) if s==part then if (v.p-start.p).magnitude < dis then print("2") |
|
|
| Report Abuse |
|
|
alexmach1
|
  |
| Joined: 02 May 2008 |
| Total Posts: 1977 |
|
|
| 21 Jul 2011 10:08 AM |
| all the ends are in the right places, only it prints 1 in the output, but never prints 2. |
|
|
| Report Abuse |
|
|