VRope - cut the rope style, verlet integrationMonkey Programming Forums/User Modules/VRope - cut the rope style, verlet integration
| I ported the VRope lib to Monkey today. It lets you do a "cheap" rope effect between two points. It is a perfect combo with a box2D joint to achieve something that looks like rope without having to create a complex chain out of many physics bodies.|
The demo above consists of two rectangle box2d bodies connected via a RopeJoint and then a VRope layered on top.
The VRope would be updated like so:
[bbcode]Local tempVec1:b2Vec2 = ropeBox1.GetWorldCenter()
Local tempVec2:b2Vec2 = ropeBox2.GetWorldCenter()
rope.Update(delta, tempVec1.x, tempVec1.y, tempVec2.x, tempVec2.y) 'delta is a float from 0.0 - 1.0 indicating 1 second[/bbcode]
And rendered like so:
[bbcode]For Local index:= 0 Until rope.numPoints - 1
DrawLine(rope.points[index].x, rope.points[index].y, rope.points[index + 1].x, rope.points[index + 1].y)
Find the module code here:
Enjoy, for free :D
| Terrific! |
| Nice addition. |
| Just played around with it and got:|
/b2ropejointdef.monkey<41> : Error : Type 'Number' not found
Method Initialize:Void(bA:b2Body, bB:b2Body, anchorA:b2Vec2, anchorB:b2Vec2, maxLength:Number)
Whats this secret number class? Something you like to share with us?
Just changed it to float.
C:/Monkey/modules/vbox2d/dynamics/joints/b2ropejointdef.monkey<44> : Error : Unable to find overload for GetLocalPoint(b2Vec2).
Will have to wait for example code for futher investigations...
| There seems to be a lot of missing code.|
compared to your demo. ;). (Physics wise).
Looks good though.
| Oh the code for the physics is box2d so not technically missing, just me being lazy and not posting a demo hah! |
| Thanks Volker I tweaked the "number". It was because it was ported from flash where a float is defined as Number (bit weird).|
I also added a basic example to the Vrope repo.
| Updated repo, anyone following this please update your link. |
| Hey Skn3, |
i hope you are still active :)
After trying to port the exactly same code to monkey, i found your version on GitHub.
Well, your's way better then my attempt, but still not what i want.
The reason i ask here, is that i need the Verlet rope as some kind of rope which is defined by a max length (think about the Box2d Joint 'Rope'), so that it will be almost linear, if the distance between two bodys is greater then the intial distance.
Unfortunatly, i cant get this to work.
Here is a screenshot of the problem (i painted in the red line, its the rope joint almost fully extended)
Since iam to dumb to understand the algorithm, i really dont know where to "insert" my tweak.
I thought about reducing the number of segments - that helps, but not at all (and look stupid in the end) or chaning the point placement (i am confused about the vars at the line)
format_code('points[index] = New VPoint(x1 + (diffVectorX * (1.0 / ccpLength)) * (multiplier * index * (1 - antiSagHack)), y1 + (diffVectorY * (1.0 / ccpLength)) * (multiplier * index * (1 - antiSagHack)))')
I inserted here a linear interpolation of the two end points by index / maxPoints. Its still not working.
The third thing i tried was to increase the "stiffness" by changing the VStick.Contract() function (the 0.5 factor) - still no success.
I really dont need any complete code, but i would love to get an idea where i should start to tweak with some variables.
Btw: Your demo and the rope joint in it is exactly what i try to achieve. Maybe its PixelToMeter scale that fails? Is my whole scene "too small" ? :(
After several hours in adjusting values by factors, i found out that this is no behaviour caused by "to long sticks", its a behaviour caused by the gravity.
It seems that the preimplemented gravity was way to high :/
The Reason for that is simple: I use another scaling than default Box2d "renderer". If anyone else is facing this problem, try to adjust the Gravity FIRST
format_code('Field gravityY:= 9.8 * Box2Definition.BOX2D_PIXEL_TO_METER_SCALE')
thats my "solve". This const is defined by 1.0 / 100.0, which means that 100 pixels are 1 meter :)
| Did you get this fully sorted? You could also try decreasing teh number of links in the rope. |