• Hey Guest! Ever feel like entering a Game Jam, but the time limit is always too much pressure? We get it... You lead a hectic life and dedicating 3 whole days to make a game just doesn't work for you! So, why not enter the GMC SLOW JAM? Take your time! Kick back and make your game over 4 months! Interested? Then just click here!

Legacy GM Trouble using lengthdir to find point on sprite

PulseNS

Member
Hi,

I'm creating a top down game based in space and have the spacecraft booster effects as a separate sprite.
The spacecraft has two booster points and I have saved them into an array boosterX and boosterY.

My problem is that I just can't seem to get the boosters to line up properly. They are always slightly out or just not rotating properly.

The sprite is 24 x 16 and the origin is centred.

I have this so far,
Create
Code:
// Booster Locations relative to origin
boosterX[0] = 0;
boosterY[0] = 3;

boosterX[1] = 0;
boosterY[1] = sprite_height - boosterY[0];
Draw
Code:
var spr = sBooster;

for(var i = 0; i < array_length_1d(boosterX); i++) {
    var relativeX = x - sprite_width/2 + boosterX[i];
    var relativeY = y - sprite_height/2 + boosterY[i];
    
    var boostX = x - lengthdir_x(x-relativeX,image_angle);
    var boostY = y - lengthdir_y(y-relativeY,image_angle);

    draw_sprite_ext(spr,0,boostX,boostY,1,1,image_angle,c_white,1);
}
Here is the output. The red circles are where the code calculates at, the blue arrows point towards where it should be.


This is probably extremely simple and staring me in the face, any help would be appretiated.
 

TheouAegis

Member
boosterX[0] = 0;
boosterY[0] = 3;
boosterX[1] = 0;
boosterY[1] = sprite_height-boosterX[0];
boosterA[0] = point_direction(0,0,boosterX[0],boosterY[0]);
boosterD[0] = point_distance(0,0,boosterX[0],boosterY[0]);
boosterA[1] = point_direction(0,0,boosterX[1],boosterY[1]);
boosterD[1] = point_direction(0,0,boosterX[1],boosterY[1]);

var i = 0; repeat 2
draw_sprite_ext(spr,0,x+lengthdir_x(boosterD,boosterA+image_angle), y+lengthdir_y(boosterD,boosterA+image_angle), 1, 1, image_angle, c_white, 1);
 

PulseNS

Member
Fantastic thank you.
I had to edit it slightly but got it working with this;

Create
Code:
boosterA[0] = point_direction(sprite_xoffset,sprite_yoffset,boosterX[0],boosterY[0]);
boosterD[0] = point_distance(sprite_xoffset,sprite_yoffset,boosterX[0],boosterY[0]);
boosterA[1] = point_direction(sprite_xoffset,sprite_yoffset,boosterX[1],boosterY[1]);
boosterD[1] = point_distance(sprite_xoffset,sprite_yoffset,boosterX[1],boosterY[1]);
 
Top