Chain between two moving objects for moving blocks

Adanos

Member
Hi there!

I am trying to create a chain object between two player objects, which can move independently from each other. The plan is, that this chain could move a specific object and the chain could go trough any other objects.
I have found the a code for creating a chain, and it works perfectly, if I only want to use the Draw function, but as an object it making a real lasershow.
Currently it looks like this:

GML:
xDist = obj_testplayer1.x - obj_testplayer2.x;
yDist = obj_testplayer1.y - obj_testplayer2.y;

chainWidth = sprite_get_width(spr_chain);
chainLength = abs(sqrt( sqr(xDist) + sqr(yDist) ));
chainAngle = degtorad(point_direction(obj_testplayer1.x, obj_testplayer1.y, obj_testplayer2.x, obj_testplayer2.y));

if (keyboard_check_pressed(vk_space))
{
    if (spacePressed ==  true)
    {
        spacePressed = false;
    }
    else
    {
        spacePressed = true;
    }
}

if spacePressed == true
{
for(var i = 0; i < chainLength; i += chainWidth)
    {
          draw_sprite_ext(spr_chain, 0, obj_testplayer1.x + ( cos(chainAngle) * i ) + ( cos(chainAngle) * (chainWidth/2) ), (obj_testplayer1.y - ( sin( chainAngle ) * i )) + (sin( chainAngle ) * (chainWidth/2) ), 1, 1, radtodeg(chainAngle), c_white, 1);
    }
}
Can anybody help, so it will work as an object, and i can move a block in the right direction?
And if I only want to move a specific object should I add an extra instance for the chain and objects?

I have only started learning programming in GML (no other language) last week and this will be my first project.
 
Top