neutro
Member
Hi guys,
So, now I am working on a simple enemy AI system.
I have the enemy oEvilFrosty1.
I have the object oPatrolTrigger, in the Instances layer, 2 instances of it that my oEvilFrosty1 is gonna patrol between.
oEvilFrosty1 Create Event:
oEvilFrosty1 Step Event:
Frosty starts, patrols towards the left, collides with the oPatrolTrigger, sprite image mirrors correctly, patrols right, then there is this second instance of oPatrolTrigger and I can't really solve how to get Frosty to do the collide and turn around while patroling towards the right. I tried a bunch of different ifs, if else and nested if-statements all through the day. Anyone got any suggestions how to solve this?
Kind regards,
Fred
So, now I am working on a simple enemy AI system.
I have the enemy oEvilFrosty1.
I have the object oPatrolTrigger, in the Instances layer, 2 instances of it that my oEvilFrosty1 is gonna patrol between.
oEvilFrosty1 Create Event:
GML:
hsp = 0.2;
vsp = 0;
grv = 0.14;
GML:
// gravity
vsp += grv;
// x collide
if (place_meeting(x+hsp,y,oWall)) {
while (!place_meeting(x+sign(hsp),y,oWall)) {
x += sign(hsp);
}
hsp *= -1;
}
// y collide
if (place_meeting(x,y+vsp,oWall)) {
while (!place_meeting(x,y+sign(vsp),oWall)) {
y += sign(vsp);
}
vsp = 0;
}
// turn around
if (place_meeting(x,y+1*sign(hsp),oPatrolTrigger)) {
hsp = -0.2;
}
// move
image_xscale = sign(hsp);
x += -hsp;
y += vsp;
Kind regards,
Fred