Legacy GM [SOLVED] Object Refuses to Move

M

Matthew German

Guest
I am having trouble in Game Maker and I can't figure out what I'm doing wrong.

Basically I have an enemy in the middle of a room and an invisible object next to it that if the player collides with, it will set off a variable that causes the enemy to move towards the player.

This is my code, in the create event for the enemy I have a code block that says:

global.asleep1 = true;

Then for the invisible object I have a collision event with the player object with a code block that says:

global.asleep1 = false;

Then, in the enemy's step event, I have:

if global.asleep1 = false
{
move_towards_point(obj_player.x, obj_player.y, 6)
}

Yet when I put this into practice, the enemy does nothing and stays completely stationary. I've tried a number of different methods and I can't get it to work.

Maybe I'm just really bad at this, I don't know. But I can't figure out why it's not working.
 
W

Wraithious

Guest
The code looks fine, are either enemy object or the invisible object set to solid? If so that may be why, to test this just put
Code:
move_towards_point(obj_player.x, obj_player.y, 6)
in the enemy's step event, if it doesn't move thats the problem, if the enemy moves then there's something else amidst
 
M

Matthew German

Guest
I'll try it out. I have gotten it to move before just as a move in direction action in its create event, and also there's an action that causes a game over (represented by the game exiting until I can make a gave over screen and menu) if it collides with the player object that works fine as well. It's just this that refuses to work.
 
J

JFitch

Guest
Are more enemies being created? If another enemy is created, global.asleep1 will be set back to true.
 
M

Matthew German

Guest
Are more enemies being created? If another enemy is created, global.asleep1 will be set back to true.
They are not, this is the only enemy in this room, and other enemies will be spawned with different objects to differentiate in later rooms.
 

Perseus

Not Medusa
Forum Staff
Moderator
First of all, try not to use global variables for such things, since they can lead to issues if multiple instances of the enemy object exist in the room. You can make it an instance variable then use explicit scope (instance.variable) to change its value.

Secondly, have you tried debugging the game to see what the values of some certain variables are after the concerned collision happens? You can put some draw_text calls in the Draw event to track what the values of global.asleep1, speed and direction are as things happen. It is possible that a collision doesn't get detected at all and the global variable never gets set to false. That might happen if the "invisible" object doesn't have a valid collision mask. Make sure it has been assigned a sprite then made invisible via the Visible checkbox, so that it gets a mask. Or set a mask directly via the object properties or by using mask_index. Also, try putting a show_message or show_debug_message call in the Collision event to see whether it runs or not.

If that doesn't help you, I'm afraid you will have to provide more information, since the setup you've got and mentioned here should work fine unless the above is the case.
 
M

Matthew German

Guest
First of all, try not to use global variables for such things, since they can lead to issues if multiple instances of the enemy object exist in the room. You can make it an instance variable then use explicit scope (instance.variable) to change its value.

Secondly, have you tried debugging the game to see what the values of some certain variables are after the concerned collision happens? You can put some draw_text calls in the Draw event to track what the values of global.asleep1, speed and direction are as things happen. It is possible that a collision doesn't get detected at all and the global variable never gets set to false. That might happen if the "invisible" object doesn't have a valid collision mask. Make sure it has been assigned a sprite then made invisible via the Visible checkbox, so that it gets a mask. Or set a mask directly via the object properties or by using mask_index. Also, try putting a show_message or show_debug_message call in the Collision event to see whether it runs or not.

If that doesn't help you, I'm afraid you will have to provide more information, since the setup you've got and mentioned here should work fine unless the above is the case.
Hey, thanks for the response! I actually figured out what was wrong- I didn't have a sprite on the invisible object, I was trying to use it both as a controller object and a physical invisible object and it didn't work. But I'll keep what you said in mind for later attempts!
 
Top