How do you find the position of objects in Game Maker?

I am making a game in Game Maker right now and cannot figure out how to get the exact position of the objects and move another object to this position. Can someone please help me?

+4
source share
2 answers

To get the position of an object, simply use

xpos = instance.x; ypos = instance.y; 

where instance is the identifier of the instance (obtained through some method, the identifier of the object can be used if the instance is the only instance of the object).

To start moving in a direction, you must set the speed and direction:

 direction = point_direction(x,y, instance.x, instance.y); speed = WANTEDSPEED; 
+6
source

The position of the object is two variables (x, y)

You can access them, as with any other variable (objectName.variable)

So these two will be, as Paul said:

 object.x object.y 

To make the object move to a point, you can better use this built-in function:

 move_towards_point(object.x,object.y,speed) 

It will move at the speed pixels every time it is executed, so you can put it in the Step event.

+1
source

All Articles