point_direction

语法:

point_direction(x1, y1, x2, y2)


参数 描述
x1 向量组件的第一个x坐标
y1 向量组件的第一个y坐标
x2 向量组件的第二个x坐标
y2 向量组件的第二个y坐标


返回: Real(实数)


描述

这个函数返回由特定的相对于房间的x/y坐标组件(x1,y1)和(x2,y2)形成的一个向量的方向。For example, in the image below if we want to get the direction from the player ship position to the enemy position so that we can fire a missile at the enemy then we would use this function (the exact code is in the example below the image):


例如:

var ex, ey;
ex = instance_nearest(x, y, enemy).x;
ey = instance_nearest(x, y, enemy).y;
with (instance_create_layer(x, y, "Bullets", obj_Missile))
   {
   direction = point_direction(x, y, ex, ey);
   }

The above code will get the x and y coordinates of the nearest enemy and then pass them to a bullet object to use in the point_direction function to set its direction of travel correctly.