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: Y MY TRIANGLE CREATIN FUNCTION NO WORK? ._.

Previous Thread :: Next Thread 
Radioaktiivinen is not online. Radioaktiivinen
Joined: 25 Apr 2009
Total Posts: 18629
22 Nov 2011 10:05 AM

--create triangle using 2 wedges
function CreateTriangle(a,b,c,offset)
local corners={a,b,c}
local longest=1
local dist=(a-b).magnitude
for i=2,3 do
local cur=corners[i]
local next=corners[i%3+1]
local tdist=(cur-next).magnitude
if tdist>dist then
longest=i
dist=tdist
end
end
corners={corners[longest],corners[(longest)%3+1],corners[(longest+1)%3+1]}
local dir=(corners[2]-corners[1]).unit --from corner 1 to 2
local projectedp=corners[1] + (dir:Dot(corners[3]-corners[1]) * dir) --point on line 1-2 with 90 degree angle to corner 3
local dir2=(corners[3]-projectedp).unit --from the projectedp to corner 3 (90 deg angle to dir)
local up=dir2:Cross(dir) --where the triangle faces
local p1=(corners[1]+corners[3])/2 + offset*up --pos of first triangle
local p2=(corners[3]+corners[2])/2 + offset*up --pos of second triangle
--cframe of first triangle (these not right propably, i tried to get it work by changing em)
local c1=CFrame.new(p1.x,p1.y,p1.z,
-up.x,-up.y,-up.z,
dir2.x,dir2.y,dir2.z,
-dir.x,-dir.y,-dir.z
)
--cframe of second triangle
local c2=CFrame.new(p2.x,p2.y,p2.z,
up.x,up.y,up.z,
dir.x,dir.y,dir.z,
dir2.x,dir2.y,dir2.z
)
--make triangles
local w1=Instance.new("WedgePart")
w1.formFactor="Symmetric"
w1.Size=Vector3.new(1,(projectedp-corners[3]).magnitude,(projectedp-corners[1]).magnitude)
w1.BottomSurface=0
w1.TopSurface=0
w1.CFrame=c1
w1.Anchored=true
local w2=Instance.new("WedgePart")
w2.formFactor="Symmetric"
w2.Size=Vector3.new(1,(projectedp-corners[2]).magnitude,(projectedp-corners[3]).magnitude)
w2.BottomSurface=0
w2.TopSurface=0
w2.CFrame=c2
w2.Anchored=true
--return unparented triangles and the up direction of the triangle
return {w1,w2},up
end


Its not working :c
The triangles always face weird directions when they should face some axis aligned direction. y they so nubs? :c
Report Abuse
ArceusInator is not online. ArceusInator
Joined: 10 Oct 2009
Total Posts: 30553
22 Nov 2011 10:07 AM
If it's not working you probably scripted it wrong.
Report Abuse
Radioaktiivinen is not online. Radioaktiivinen
Joined: 25 Apr 2009
Total Posts: 18629
22 Nov 2011 10:12 AM
no u.

I checked the directions and positions and they seem to be fine, but for some reason when i make the cframe/welds the rotation is all messed up.
Report Abuse
Radioaktiivinen is not online. Radioaktiivinen
Joined: 25 Apr 2009
Total Posts: 18629
22 Nov 2011 10:13 AM
*wedgeparts, not welds
Report Abuse
Trioxide is not online. Trioxide
Joined: 29 Mar 2011
Total Posts: 32902
22 Nov 2011 10:15 AM
[ Content Deleted ]
Report Abuse
Radioaktiivinen is not online. Radioaktiivinen
Joined: 25 Apr 2009
Total Posts: 18629
22 Nov 2011 10:17 AM
Stupid wiki doesnt tell a thing about CFrames, whoever wrote the CFrame article shall fail.


It doesnt event tell if roblox uses right or left handed coord system or what the R01 blah blah represent in creating a cframe cuz idk if roblox uses row or column matrix thingie. -.-
Report Abuse
Radioaktiivinen is not online. Radioaktiivinen
Joined: 25 Apr 2009
Total Posts: 18629
22 Nov 2011 10:21 AM
I dislike triangles now.

Roblox is a blocky game, it would ruin it if we had triangles.


Everything must be blocks. BLOCKS BLOCKS BLOCKS!!!111






go awai.
Report Abuse
ArceusInator is not online. ArceusInator
Joined: 10 Oct 2009
Total Posts: 30553
22 Nov 2011 10:21 AM
The sides on the WedgeParts and CornerWedgeParts are totally messed up. If I'm not mistaken, the slant of a WedgePart is on the left.
Report Abuse
Radioaktiivinen is not online. Radioaktiivinen
Joined: 25 Apr 2009
Total Posts: 18629
22 Nov 2011 10:24 AM
Wat?


So thats why it didnt work :c

i assumed the slant to be on z axis, as i remember that the front face would be there too...


Unless the front face is not on z axis for some reason -.-
Report Abuse
ArceusInator is not online. ArceusInator
Joined: 10 Oct 2009
Total Posts: 30553
22 Nov 2011 10:33 AM
Welcome to roblox logic.
Report Abuse
Radioaktiivinen is not online. Radioaktiivinen
Joined: 25 Apr 2009
Total Posts: 18629
22 Nov 2011 10:34 AM
Theres no such place u.
Report Abuse
Trioxide is not online. Trioxide
Joined: 29 Mar 2011
Total Posts: 32902
22 Nov 2011 11:13 AM
[ Content Deleted ]
Report Abuse
Radioaktiivinen is not online. Radioaktiivinen
Joined: 25 Apr 2009
Total Posts: 18629
23 Nov 2011 10:53 AM
BUMP!

How do the object space axises on wedges go?

Like wich direction x,y and z axises point?

I assume y axis points up, but does z axis go from the back of the wedge to the front (though the back, and then through the slant), or does it go from side to side?
Report Abuse
xJavaScriptx is not online. xJavaScriptx
Joined: 17 Nov 2011
Total Posts: 72
23 Nov 2011 11:05 AM
[ Content Deleted ]
Report Abuse
Trioxide is not online. Trioxide
Joined: 29 Mar 2011
Total Posts: 32902
23 Nov 2011 11:10 AM
[ Content Deleted ]
Report Abuse
xJavaScriptx is not online. xJavaScriptx
Joined: 17 Nov 2011
Total Posts: 72
23 Nov 2011 11:12 AM
[ Content Deleted ]
Report Abuse
Trioxide is not online. Trioxide
Joined: 29 Mar 2011
Total Posts: 32902
23 Nov 2011 11:13 AM
[ Content Deleted ]
Report Abuse
xJavaScriptx is not online. xJavaScriptx
Joined: 17 Nov 2011
Total Posts: 72
23 Nov 2011 11:15 AM
You can be a snitch anywhere.
Report Abuse
Radioaktiivinen is not online. Radioaktiivinen
Joined: 25 Apr 2009
Total Posts: 18629
23 Nov 2011 11:15 AM
Now i got them to be on the right plane...

but theyre still rotated wrong and are glitching roblox's rendering.
Report Abuse
Trioxide is not online. Trioxide
Joined: 29 Mar 2011
Total Posts: 32902
23 Nov 2011 11:15 AM
[ Content Deleted ]
Report Abuse
Radioaktiivinen is not online. Radioaktiivinen
Joined: 25 Apr 2009
Total Posts: 18629
23 Nov 2011 11:31 AM
YAY IT WORKS!

CreateTriangle(corner1,corner2,corner3,offsetofwedgestowardsfacingdirectionoftriangleinstuds,thicknessofwedges)

Here chu go:

--Create triangle out of 2 wedges given the corners and an offset for the triangles in the triangles facin direction.
function CreateTriangle(a,b,c,offset,thickness)
if thickness==nil then thickness=1 end
if offset==nil then offset=0 end
local corners={a,b,c}
local adist=(a-b).magnitude
local bdist=(b-c).magnitude
local cdist=(c-a).magnitude
if bdist>adist and bdist>cdist then
corners={b,c,a}
elseif cdist>adist and cdist>bdist then
corners={c,a,b}
end
adist=nil
bdist=nil
cdist=nil

local A=corners[1]
local B=corners[2]
local C=corners[3]

local dir=(B-A).unit
local proj=A + (dir:Dot(C-A) * dir)
local dir2=(C-proj).unit
local up=dir:Cross(dir2)
print(up.magnitude)
local pos1=(A+C) / 2 + (offset*up)
local pos2=(C+B) / 2 + (offset*up)
local c1=CFrame.new(
pos1.x,pos1.y,pos1.z,
up.x,up.y,up.z,
-dir.x,-dir.y,-dir.z,
-dir2.x,-dir2.y,-dir2.z
)
local c2=CFrame.new(
pos2.x,pos2.y,pos2.z,
up.x,up.y,up.z,
dir2.x,dir2.y,dir2.z,
-dir.x,-dir.y,-dir.z
)
local w1=Instance.new("WedgePart")
w1.formFactor="Custom"
w1.Size=Vector3.new(thickness,(A-proj).magnitude,(proj-C).magnitude)
w1.TopSurface=0
w1.BottomSurface=0
w1.Anchored=true
w1.CFrame=c1
local w2=Instance.new("WedgePart")
w2.formFactor="Custom"
w2.Size=Vector3.new(thickness,(proj-C).magnitude,(B-proj).magnitude)
w2.TopSurface=0
w2.BottomSurface=0
w2.Anchored=true
w2.CFrame=c2
return {w1,w2},up
end

CreateTriangle(Vector3.new(0,0,0),Vector3.new(0,0,10),Vector3.new(0,10,8),0.5,1)
Report Abuse
NXTBoy is not online. NXTBoy
Joined: 25 Aug 2008
Total Posts: 4533
23 Nov 2011 01:32 PM
Try my geometry library. It's in my models, and has the function you need.

Also, Y U NO INDENT YOUR CODE?
Report Abuse
Radioaktiivinen is not online. Radioaktiivinen
Joined: 25 Apr 2009
Total Posts: 18629
23 Nov 2011 01:46 PM
No i dont want ur code.
Does indenting even work on the forums??? Too lazy to indent as roblox doesnt have support for it so its annoying to tab every line.
Report Abuse
NXTBoy is not online. NXTBoy
Joined: 25 Aug 2008
Total Posts: 4533
23 Nov 2011 02:00 PM
> Does indenting even work on the forums???

Not really. However, I can still see _whether_ you indented it. Posts made with the forum enhancer preserve indentation. But I digress.

You shouldn't be indenting just for the forums. You should be doing it because that's how software is done.

In what sense does "roblox not have support for it"?
Report Abuse
NXTBoy is not online. NXTBoy
Joined: 25 Aug 2008
Total Posts: 4533
23 Nov 2011 02:01 PM
> No i dont want ur code.

You don't need to use my code. I'm suggesting you read through it. I don't remember it taking more than 15 lines to do what you're doing.
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