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?
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.
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.
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.
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;
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With