GameMaker <solved> what is best usage of lengthdir?

J

jb skaggs

Guest
OK I have trying to use lengthdir, for attaching parts to an object and keeping them in place when I rotate the object.

I thought I had this figured out. Until I began to try and align the objects and I found that the lengthdir code I have changes the x,y of the initial starting place as soon as I place it.

Basically I want to place an object adjacent to the parent or core object and lock that in place relative to the parent object so I can move and rotate all the objects as a whole.

The object is created with a left_released at mouse_x, mouse_y, but then it shifts slightly after creation moving out of alignment.

here is the code:



Code:
//creation event:

distance_from_core = point_distance(x, y, o_core.x, o_core.y);
angle_dif = angle_difference(point_direction(o_core.x,o_core.y,x,y), o_core.image_angle);
s=o_ship_list.s
o_ship_list.s++;
o_ship_list.ship_list[s,0]=x;
o_ship_list.ship_list[s,1]=y;


//step event:

x = o_core.x + lengthdir_x(distance_from_core, angle_dif + o_core.image_angle);
y = o_core.y + lengthdir_y(distance_from_core, angle_dif + o_core.image_angle);
image_angle=o_core.image_angle;
 
J

jb skaggs

Guest
The problem was there was a cursor obj that was in correct position, so the error was in the left_released creation event of the object making this one. SO in the instance_create_layer I changed the mouse_x to o_part_cursor.x and it fixed it.
 
Top