Rexzqy
Member
Hi, so I am making a sound system where the enemy will track the sounds you or npcs make. My code is basically finding the loudest sound and the enemy will run toward it if they are within a certain distance. It works ok when theres only 1 of them, however, lets say 2 enemies are far away from each other, and 2 separate sounds were made by each of the enemies. Only the first sound created would be recognized and the one nearby would walk to it and the second enemy wouldnt move to the second sound. Any help is appreciated! Below is my code:
if instance_exists(obj_sound)&&obj_sound.magnitude >= 50
{
var max_sound = noone;
var max_sound_num = -1;
with(obj_sound)
{
if (max_sound == noone || sound>max_sound_num)
{
max_sound = id;
max_sound_num = sound;
}
/// this is for finding out the loudest sound
}
if distance_to_object(max_sound)<100
{
mp_potential_step(max_sound.x,max_sound.y,cspd,false);
}
if (x = obj_sound.x&& y = obj_sound.y)||state=states.alert
{
instance_destroy(max_sound);
}
/// this is the code that make enemy run toward the sound
}
EDIT: Sry for my broken english, maybe a better way to phrase this is: can there be multiple "Loudest Sound" for enemies at different positions?
if instance_exists(obj_sound)&&obj_sound.magnitude >= 50
{
var max_sound = noone;
var max_sound_num = -1;
with(obj_sound)
{
if (max_sound == noone || sound>max_sound_num)
{
max_sound = id;
max_sound_num = sound;
}
/// this is for finding out the loudest sound
}
if distance_to_object(max_sound)<100
{
mp_potential_step(max_sound.x,max_sound.y,cspd,false);
}
if (x = obj_sound.x&& y = obj_sound.y)||state=states.alert
{
instance_destroy(max_sound);
}
/// this is the code that make enemy run toward the sound
}
EDIT: Sry for my broken english, maybe a better way to phrase this is: can there be multiple "Loudest Sound" for enemies at different positions?
Last edited: