Unwanted Delay W/ Collision Event

T

Tchoup15

Guest
Hi, so I am trying to build a stealth aspect into the game. When my player (obj_heroteam) moves, it creates obj_sound (not solid), which is (at the moment) represented as a white circle around him that lasts half a second before being destroyed, with a radius of 250. I want my enemy characters (obj_enemy) to move towards obj_heroteam when he "hears" him, or when he collides with the obj_sound.

My issue is that as long as obj_enemy is within obj_sound, so while the collision event keeps happening, the obj_enemy doesn't move, he waits until after the collision to begin moving.

Here's where I am at:



Under obj_enemy Create Event

sprite_index = spr_enemy;
var_speed = 2;
var_distance = distance_to_object(obj_heroteam);
can_hear = false;



Under obj_enemy Collision event with obj_sound:

can_hear = true;



Under obj_enemy Step Event:

if (can_hear = true) {
sprite_index = spr_enemynoise;
img_speed = 1;
mp_potential_step(obj_heroteam.x, obj_heroteam.y, var_speed, false);
}


Any advice for making sure that the obj_enemy doesn't stall?

(Side note: I created the can_hear = true / can_hear = false, because, as a next step, I want to add code to the obj_enemy step event where, after the obj_enemy is a certain distance away from obj_heroteam, an alarm is triggered and after a couple seconds can_hear = false and the character stops chasing the obj_heroteam. Basically, the next step is after the hero gets far enough away from the enemy, the enemy gets bored and stops chasing.)

Thanks guys!
 
You may try using position_meeting like this instead of the collision event.
Code:
//Step Event of chaser object aka enemy.
if ( position_meeting(x,y,obj_sound) )
{
 can_hear = true;
} else { can_hear = false; }
 
T

Tchoup15

Guest
Thanks Turkish Coffee! That worked!

Follow up question - I tried switching out can_hear = false, to an alarm to add a bit of a delay:

Code:
//Step Event of chaser object aka enemy.
if ( position_meeting(x,y,obj_sound) )
{
 can_hear = true;
} else {alarm[0] = room_speed*3; }

And made the alarm[0]:
Code:
can_hear = false;
sprite_index = spr_enemy;
However, for whatever reason, can_hear never change to false, and the obj_enemy just keeps following obj_hero. Any insight?


Thanks again :)
 

3dgeminis

Member
Because the alarm is always in 90. What I do is I emulate an alarm with a variable
CREATE
Code:
timer=0
STEP
Code:
if ( position_meeting(x,y,obj_sound) )
{
 can_hear = true;
 timer=room_speed*3
}
else {if timer>0 {timer-=1} else {can_hear=false} }
 
Top