Lengthdir_x - hpgDesigns/hpgdesigns-dev.io GitHub Wiki

Notation

Description

lengthdir_xy.svg.]] Gives the horizontal component of a vector with the given length and direction; this can be thought of as the terminal x-coordinate of a vector at (0,0). It may help to think of the input as the depiction of a right triangle, where the length is the hypotenuse and the direction is the angle.

Bear in mind that the return value is only the horizontal component of the input vector; you will generally want to add this value to a coordinate.

This function is generally used with its sister function lengthdir_y().

Parameters

  • len: length of the vector; the hypotenuse of the right triangle, or the distance between (0,0) and the desired point
  • dir: direction in degrees of the vector; the angle of the right triangle, or the direction from (0,0) to the desired point

Return Values

double: Returns the horizontal component of the given vector.

Example Call

// Create a circle of ten coin objects 64px from this object
for (int dir = 0; dir < 360; dir += 36) // Loop through all directions from 0 to 360 in increments of 36, so 10 directions
{
  instance_create(x + lengthdir_x(64, dir), y + lengthdir_y(64, dir), obj_coin); // Create a coin 64px out in each direction
]

NOTOC

Category:Function:Real