|
Post by GMLWaffle on Sept 28, 2016 20:25:05 GMT -6
So following the creation of the Ragdoll Physics example, I decided to play around and see if I could create a system for creating physics ropes in GameMaker. Here's the result! The rope reacts perfectly to collision with the walls, and itself. To add things to it's collision group, parent your object to con_dynamic_parent. As you can see there is a little bit of gaps or spaces between each individual rope object being created, which is partially due to my laziness to edit the math for creating it any further. If you want it to look like a more perfect "rope" all you have to do is change the sprite in use from an 8x16 to something square like 8x8 or 4x4. This also requires you changing the variables ropeY and jointY to accommodate for the distance being lost to the sprites size. All in all it turned out pretty great! Here's the code for actually creating the rope objects and their joints: ropeY = 0; jointY = 10;
for (rope = 0; rope <= 10; rope += 1) { if (rope = 0) { rope2 = instance_create(x,ropeY+4,obj_ropeStart); ropeY += 16 } else if (rope > 0) { rope1 = instance_create(x,ropeY,obj_rope); ropeY += 16; physics_joint_revolute_create(rope2,rope1,x,jointY,0,0,0,0,0,0,0); jointY += 16; rope2 = instance_create(x,ropeY,obj_rope); ropeY += 16; physics_joint_revolute_create(rope1,rope2,x,jointY,0,0,0,0,0,0,0); jointY += 16; } }
instance_destroy();
If you wish to make the rope longer or shorter all you have to do is change the second argument in the for loop from rope <= 10 to whatever length you desire! Here's the link to download the .gmz! Click Me to Download!
|
|
|
Post by GMLWaffle on Sept 28, 2016 20:27:27 GMT -6
Something else to think about with this example:
This doesn't have to only apply to ropes. You could use an altered version that creates obj_ropeStart at the beginning and the end of the "rope" to create things like bridges, wires for holding things up in a physics world, nets for the player to grab, webs for a Spider-Man like game, and all sorts of other things! Don't limit the title of an example to the possibilities it has in store!
|
|
|
Post by illdiewithoutpi on Sept 28, 2016 21:05:57 GMT -6
Thanks, I've been wanting to look into how GM physics works and this and the ragdoll project should be pretty helpful :D
|
|
|
Post by GMLWaffle on Sept 28, 2016 21:23:11 GMT -6
Thanks, I've been wanting to look into how GM physics works and this and the ragdoll project should be pretty helpful No problem! I'll start a video series on Physics soon enough. But the requests keep coming in from YouTube so I'll have my hands full for a little while anyway!
|
|