Returns the horizontal x-component of the vector determined by the indicated length and direction.


lengthdir_x(len, dir);

Argument Description
len The length away of the point to return.
dir The direction of the point to return.

Returns: Real


This function seems confusing at first, but it's not really. It is used to get the x component of a position "len" pixels from the starting point and in direction "dir". Imagine a circle around your instance, then imagine a point anywhere on that circle. To move to that point we need to move the object so many pixels in that direction... so this function (when used with lengthdir_y) gets the position of that point on the circle to be used in code by the instance. See the image below for details:


instance_create(x + lengthdir_x(64, image_angle), y + lengthdir_y(64, image_angle), obj_bullet);

This will create a bullet instance at (x,y), but with 64 pixels added in the direction of image_angle. This is typically used for syncing a bullets start position with the end of a gun in game.

Back: Real Number Functions
Next: lengthdir_y
© Copyright YoYo Games Ltd. 2018 All Rights Reserved