Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do you find an objects position in Game Maker?

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

like image 751
babin101 Avatar asked Jan 15 '13 21:01

babin101


People also ask

How do you move objects in GameMaker?

Remember, in a GameMaker room, to move right we add to the x position and to move left we subtract, so this code will give us a positive or negative value that we can add or subtract to move horizontally or vertically depending on the keyboard input.

How do you make an object move towards the mouse in GameMaker?

If, on the other hand, you want the object to literally follow the cursor around the screen (so that it is always moving towards the cursor, but not necessarily in the same position as it), drag the "Move towards" icon into the Actions box. It is the one that looks like an arrow pointing to a little dot.

What is a variable in GameMaker?

USING VARIABLES IN GAMEMAKER. A variable is a general programming term for something that can store information. In GameMaker, variables can either store a number or some text.


Video Answer


1 Answers

To get an object's position simply use

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

where instance is the instance id (gained through some method, object id can be used if the instance is the only instantiation of the object).

To start moving towards a position you should set the speed & direction:

direction = point_direction(x,y, instance.x, instance.y);
speed = WANTEDSPEED;
like image 156
paul23 Avatar answered Sep 24 '22 19:09

paul23