Generating a physics rope

C

ChiHelios

Guest
Hi all, first time posting here. Getting back into gamemaker after a long break off. Just wondering if anyone has an idea of what's going wrong with my system?

I have been building a platformer using GM physics, and want the player to be able to fling a grapple rope. When generating the rope I use a y offset so the segments don't overlap but it generates in the floor when grounded causing problems.

Would it be possible to generate the rope smartly to prevent unwanted collisions? I've thought about checking for space below, but what about oscillating the generation point up and down?
Thanks :)

This is the code I am using based on the rope tutorial.

Code:
// Initialize variables for the grapple direction
global.grappleout = true;
grapplestrength = 300;
grapple_angle = pi*point_direction(player.x,player.y,mouse_x,mouse_y)/180;
num_segments = 15;

// send it in the direction of the grapple angle
physics_apply_impulse(x,y,grapplestrength*cos(grapple_angle),-grapplestrength*sin(grapple_angle));

//Create a list to store the object ids of the rope and 💩💩💩💩
global.rope_segments = ds_list_create()

// Set the variables for the rope segments to come
offset_y = 0;
host = self;

// Create the segment and add it to the global list
next_rope = instance_create(x, y + offset_y, obj_Rope);
ds_list_add(global.rope_segments, next_rope);

attach = physics_joint_rope_create(host, next_rope, host.x, host.y, next_rope.x, next_rope.y, 10, false);
physics_joint_set_value(attach, phy_joint_damping_ratio, 0.01);
physics_joint_set_value(attach, phy_joint_frequency, 10);

// Set the parent so that the properties cascade
with(next_rope){
    parent = other.id;
}

for (i=0; i<num_segments; i+=1)
{

    offset_y += 10;
    last_rope = next_rope;
    next_rope = instance_create(x, y + offset_y, obj_Rope);
    ds_list_add(global.rope_segments, next_rope);
    
    link = physics_joint_rope_create(last_rope, next_rope, last_rope.x, last_rope.y, next_rope.x, next_rope.y, 10, false);
    
    physics_joint_set_value(link, phy_joint_damping_ratio, 0.01);
    physics_joint_set_value(link, phy_joint_frequency, 10);
    
    with(next_rope){
        parent = other.last_rope;
    }

}
 
Top