• Hey Guest! Ever feel like entering a Game Jam, but the time limit is always too much pressure? We get it... You lead a hectic life and dedicating 3 whole days to make a game just doesn't work for you! So, why not enter the GMC SLOW JAM? Take your time! Kick back and make your game over 4 months! Interested? Then just click here!

Enemy AI Collision [SOLVED)

W

Wren

Guest
I am following the 101 series on enemy AI. First two vids went well but with the third clip I have the problem that enemies will pass through solid objects as if they are air.
Did I miss collision code somewhere? In the clips it looks like the collision works without any further coding.

Player collision works fine btw.
 
W

Wren

Guest
Edit : Still no idea. In the meantime I even copied the players collision code into the enemies step event (like at the end of the vid).

Now enemies will NOT pass 64x64, but still pass through any other solid objects like doors or 32x32 walls.
 
W

Wren

Guest
I am loosing my nerves here :(

Here is the collision code for my round player sprite. Its top-down btw. It works well and the player will stop in front of any solid object.
//collision
if hspeed !=0
if !place_free(x+hspeed,y)
{
if hspeed>0 move_contact_solid (0,hspeed)
if hspeed<0 move_contact_solid (180,-hspeed)
hspeed=0
}
if vspeed !=0
if !place_free(x+hspeed,y+vspeed)
{
if vspeed>0 move_contact_solid (270,vspeed)
if vspeed<0 move_contact_solid (90,-vspeed)
vspeed=0
}

I copied the code into the enemies step event. Enemies are round sprites as well.

First they would pass through any solid object except one 64x64 wall tile. At least I found a workaround by making other walltiles a child of the initial 64x64 walltile.
Which is odd because there is not any code in the wallobjects and I just don't understand why it suddenly started working as intended.

So the next problem are my doors. A door is solid when closed and !solid when open.
Works well with the player sprite but enemies just pass through closed doors.
I tried to also child the door with obj_wall, but then the enemies will even halt at open doors.

I still have no idea whats going on for you can see in the video that the enemies stop at solid walls even without any code.
 

KurtBlissZ

Member
So the next problem are my doors. A door is solid when closed and !solid when open.
Works well with the player sprite but enemies just pass through closed doors.
I tried to also child the door with obj_wall, but then the enemies will even halt at open doors.
Can you show your code for your enemies and the player's. Pretty sure the enemies are moving differently then the player is.

Or/and If you want, post up the source and I can take a better look at your game. Since there's so many things that could be going on with your code. Do this by going file > export project or by pressing CRTL + ALT + E in your project.
 
Last edited:
W

Wren

Guest
Finally I solved it with kurts help by changing a line in the ai chasing code ( from "mp_potential_step_object(obj_player1.x,obj_player1.y,enemySpeed,true);" to "mp_potential_step(obj_player1.x,obj_player1.y,enemySpeed,false)".
Thanks kurt and thank you Theo for your eagle eye .D
 
Top