M
Monster25
Guest
Hello! I'm trying to complete my game's enemy collisions. The player is intended to collide with walls, enemies and everything object I put under obj_solid as a child but it needs to work vice-versa with enemies as well, so if an enemy is moving towards the player, he would stop when he collides with the player. This totally worked fine but when I start and try to make collisions for my enemies when they hit the player it all goes wrong. The enemies rotate towards the player and they have 2 basic states, idle and chase. Everything works fine about them, I even fixed the image angle ing up the collisions, everything is fine until they start moving. I'm not sure how I can make the code work for them. Here is the collision code from my state:
//Collision
clamp(movespeed,0,movespeedmax);
if (movespeed < movespeedmax)
movespeed = movespeed + accelerate_speed;
//Collision
if (place_meeting(x+2,y,obj_player))
speed = 0;
else
speed = movespeed;
if (place_meeting(x-2,y,obj_player))
speed = 0;
else
speed = movespeed;
if (place_meeting(x,y+2,obj_player))
speed = 0;
else
speed = movespeed;
if (place_meeting(x,y-2,obj_player))
speed = 0;
else
speed = movespeed;
As you can see I clamp the movespeed so it doesn't go over my max move speed then I use a small acceleration code so that the enemies don't move at once. Then for the collision code this is what I could come up with but they still get stuck. I've tried doing a similar collision code to my players' which is perfect but it doesn't work since I can't predict where they will move based on key strokes. They simply need to follow the player when they get in range, apart from the collision itself, everything else is perfect.
//Collision
clamp(movespeed,0,movespeedmax);
if (movespeed < movespeedmax)
movespeed = movespeed + accelerate_speed;
//Collision
if (place_meeting(x+2,y,obj_player))
speed = 0;
else
speed = movespeed;
if (place_meeting(x-2,y,obj_player))
speed = 0;
else
speed = movespeed;
if (place_meeting(x,y+2,obj_player))
speed = 0;
else
speed = movespeed;
if (place_meeting(x,y-2,obj_player))
speed = 0;
else
speed = movespeed;
As you can see I clamp the movespeed so it doesn't go over my max move speed then I use a small acceleration code so that the enemies don't move at once. Then for the collision code this is what I could come up with but they still get stuck. I've tried doing a similar collision code to my players' which is perfect but it doesn't work since I can't predict where they will move based on key strokes. They simply need to follow the player when they get in range, apart from the collision itself, everything else is perfect.