Distance_to_object() help

J

Jacob Thrasher

Guest
I don't know if this is a problem with how I am writing the distance_to_object command or if it is another issue somewhere else in my code, but I am thinking it is the former.

Essentially the way I programmed my enemy AI is to check if the player is within a certain distance of it, then it will act accordingly. There is a check for if the player is far away, near, and very close to the object. These cause the enemy to move idly, follow the player, and attack respectively. The code is as followed (extremely simplified, but I can just post the whole thing if need be. Just let me know).

if ((distance_to_object(obj_player) <= 5) && place_meeting(x,y+1,obj_wall))
{
//Perform attacking code
}
else if (distance_to_object(obj_player) > 5) && (distance_to_object(obj_player) <= 150)
{
//Perform follow code
}
else
{
//Perform idle code
}

What's happening is that the bear is getting caught up trying to transition from the following code to the attacking code. The game said the distance_to_object is reading 20 (shown on the rock), but it is still running the code under the first if branch. Here is a video:

 

YellowAfterlife

ᴏɴʟɪɴᴇ ᴍᴜʟᴛɪᴘʟᴀʏᴇʀ
Forum Staff
Moderator
A bigger snippet of code would help, but, if I was to guess, you don't have a mask index assigned for the bear object, thus causing the distance to change when the sprite changes.
 
J

Jacob Thrasher

Guest
A bigger snippet of code would help, but, if I was to guess, you don't have a mask index assigned for the bear object, thus causing the distance to change when the sprite changes.
Wow yeah you were exactly correct. The problem was fixed immediately when I messed with the mask. Thanks so much, that was getting frustrating.
 
Top