justin123 Posted August 3, 2009 Report Share Posted August 3, 2009 This script makes links to form a chain. It makes the chain move in straight lines. I need help making it curve starting at link[0] to link[8]. here's the script: for (i=0;i<=8;i+=1) { angle=point_direction(x,y,link[8].x,link[8].y); link.distance=point_distance(x,y,link[8].x,link[8].y)/8*i; link.x=x+cos(degtorad(angle))*(i+link.distance); link.y=y-sin(degtorad(angle))*(i+link.distance); link[8].x=mouse_x link[8].y=mouse_y } Thanks, Justin123 Link to comment Share on other sites More sharing options...
Smidge204 Posted August 3, 2009 Report Share Posted August 3, 2009 Could you perhaps make a graphical mock-up of what you want? Because this is either a really easy or a REALLY hard problem depending on what you want to do. =Smidge= Link to comment Share on other sites More sharing options...
justin123 Posted August 3, 2009 Author Report Share Posted August 3, 2009 Could you perhaps make a graphical mock-up of what you want? Because this is either a really easy or a REALLY hard problem depending on what you want to do.=Smidge= All really need to do is find a way to add gravity to each of the links Link to comment Share on other sites More sharing options...
LarkSS Posted August 3, 2009 Report Share Posted August 3, 2009 Could you perhaps make a graphical mock-up of what you want? Please, otherwise you probably won't be able to get much help. Link to comment Share on other sites More sharing options...
Smidge204 Posted August 4, 2009 Report Share Posted August 4, 2009 All really need to do is find a way to add gravity to each of the links That much is easy. Maintaining the links the proper distance from each other while still applying gravity to each one? A very difficult dynamic problem. I hope you're good at calculus. =Smidge= Link to comment Share on other sites More sharing options...
justin123 Posted August 4, 2009 Author Report Share Posted August 4, 2009 That much is easy.Maintaining the links the proper distance from each other while still applying gravity to each one? A very difficult dynamic problem. I hope you're good at calculus. =Smidge= I just want each of the links to hang between the 2 point instead being straight. Link to comment Share on other sites More sharing options...
flame6753 Posted August 4, 2009 Report Share Posted August 4, 2009 I think he means sort of like how the bridges work in Sonic Worlds, except applying them for the links. Link to comment Share on other sites More sharing options...
Smidge204 Posted August 4, 2009 Report Share Posted August 4, 2009 This is why I asked for a graphical representation of the desired result. =Smidge= Link to comment Share on other sites More sharing options...
Aikocho Posted August 4, 2009 Report Share Posted August 4, 2009 This is why I asked for a graphical representation of the desired result.=Smidge= :Translation: Show us what you're talking about, dude. A picture, a screenie maybe? Link to comment Share on other sites More sharing options...
Password Posted August 5, 2009 Report Share Posted August 5, 2009 ^You want something like this, justin? Link to comment Share on other sites More sharing options...
Kain Posted August 5, 2009 Report Share Posted August 5, 2009 Are you looking for something like this resembling what you'd get if you grabbed a piece of yarn at two ends or are you looking for something with less give? Also do you want the nodes to move independently based on their own physics (would move more realistically but maybe too wiggly) or just a parabolic estimation (in other words the droop moves 1:1 with the two points with no momentum)? Link to comment Share on other sites More sharing options...
justin123 Posted August 6, 2009 Author Report Share Posted August 6, 2009 [qimg]http://img29.imageshack.us/img29/7936/examplejbh.png[/qimg]^You want something like this, justin? That pretty close to what I'm trying to get. How can I make the links hang like a rope? Link to comment Share on other sites More sharing options...
LarkSS Posted August 8, 2009 Report Share Posted August 8, 2009 You could use a bezier curve, or just set the Y positions of the points using a trig function to make it curve similar to the arm ( won't look too good if you want the hand to rotate freely however ). Link to comment Share on other sites More sharing options...
justin123 Posted August 8, 2009 Author Report Share Posted August 8, 2009 You could use a bezier curve, or just set the Y positions of the points using a trig function to make it curve similar to the arm ( won't look too good if you want the hand to rotate freely however ). I'll try that. Link to comment Share on other sites More sharing options...
Smidge204 Posted August 8, 2009 Report Share Posted August 8, 2009 I managed to solve the problem using a quasi-physical simulation method: Applying "gravity" to each link and then constraining each link to a maximum distance to both of its neighbors in the chain. http://www.smidgeindustriesltd.com/LinkDemo.rar VisualBasic 6 source code included. Here's the meat of it, reduced to a pseudo-code: /*plist is a collection of links form 0 to MaxLinks */ /* Fix the start link at (280,300) */ plist(MaxLinks).X = 280 plist(MaxLinks).Y = 300 Do /* Apply simulated gravity to the link */ /* Links 0 (mouse) and MaxLinks (fixed) are exempt */ For i = 1 To MaxLinks - 1 plist(i).Y = plist(i).Y + Gravity /* ChkDist checks the distance between the link centers and, if */ /* greater than LinkLength, moves the first link to be at that */ /* maximum distance. */ ChkDist(plist(i).X, plist(i).Y, 0, LinkLength, plist(i - 1).X, plist(i - 1).Y) Next i /* Now modify link locations in the other direction, from the */ /* fixed link to the mouse (movable) end, to create a sag. */ For i = MaxLinks - 1 To 1 Step -1 ChkDist plist(i).X, plist(i).Y, 0, LinkLength, plist(i + 1).X, plist(i + 1).Y Next i /* set the last link in the chain to the mouse's position */ plist(0).X = Mouse.X plist(0).Y = Mouse.Y /* Update everything graphically */ Drawlinks Loop[/CODE]You can check the VB source for the whole thing. Files can be read using your favorite text editor.Edit: I should explain that I copy-pasted ChkDist from another, older project and it was originally intended to do a bit more than what it does here... so the arguments are kinda odd. Sorry for any confusion.=Smidge= Link to comment Share on other sites More sharing options...
justin123 Posted August 9, 2009 Author Report Share Posted August 9, 2009 I managed to solve the problem using a quasi-physical simulation method: Applying "gravity" to each link and then constraining each link to a maximum distance to both of its neighbors in the chain.http://www.smidgeindustriesltd.com/LinkDemo.rar VisualBasic 6 source code included. Here's the meat of it, reduced to a pseudo-code: /*plist is a collection of links form 0 to MaxLinks */ /* Fix the start link at (280,300) */ plist(MaxLinks).X = 280 plist(MaxLinks).Y = 300 Do /* Apply simulated gravity to the link */ /* Links 0 (mouse) and MaxLinks (fixed) are exempt */ For i = 1 To MaxLinks - 1 plist(i).Y = plist(i).Y + Gravity /* ChkDist checks the distance between the link centers and, if */ /* greater than LinkLength, moves the first link to be at that */ /* maximum distance. */ ChkDist(plist(i).X, plist(i).Y, 0, LinkLength, plist(i - 1).X, plist(i - 1).Y) Next i /* Now modify link locations in the other direction, from the */ /* fixed link to the mouse (movable) end, to create a sag. */ For i = MaxLinks - 1 To 1 Step -1 ChkDist plist(i).X, plist(i).Y, 0, LinkLength, plist(i + 1).X, plist(i + 1).Y Next i /* set the last link in the chain to the mouse's position */ plist(0).X = Mouse.X plist(0).Y = Mouse.Y /* Update everything graphically */ Drawlinks Loop[/CODE]You can check the VB source for the whole thing. Files can be read using your favorite text editor.Edit: I should explain that I copy-pasted ChkDist from another, older project and it was originally intended to do a bit more than what it does here... so the arguments are kinda odd. Sorry for any confusion.=Smidge=I try this. First I have to convert it to gml using similar functions. Link to comment Share on other sites More sharing options...
Recommended Posts