I am creating a game for a class project which involves several objects having relatively complex behaviors. Each of these objects has an “aggro” variable, and this variable determines which behavior mode the object is in, either “docile,” “interested,” or “aggressive”.
When ran, the game should start with each of the (currently 3) objects moving around within their areas, then when the player gets close the aggro variable will raise, causing the object to first slowly approach the player, then rapidly approach the player.
Instead of the expected (and intended) result, none of the objects move at al despite the aggro variable rising and falling as expected. The objects only move when the player is directly over them, and even then they seem to be bound to a small area.
Here is the code relating to the objects’ behavior:
Hi Sycharikia and welcome, hope you have fun with your game.
I don’t have solutions that will automatically fix everything but I did notice some problems.
Firstly, the first event has no conditions which means the dino object variable is always false. Later in the events when you change it to true, it’s just going to be on false anyway.You could have At the beginning of the scene as a condition or something else that works for you.
Secondly, I didn’t see where the aggro level changes apart from a couple of re-sets. You said it changes when the player gets close to a dino, is this in events not in the screenshot7
Thirdly, let’s say the aggro value of dino is 100. Then
dino aggro > 75
dino aggro > 25
dino aggro > 0
are all true which will result in conflicts between those three events.
“Done” is used to prevent more than one event from triggering. It needs to be reset to false every time like it is. The events check if it’s false and then sets it to true to prevent any other events from being triggered. That seems fine to me.
I agree, it would be helpful to see where the agro is calculated. I’m assuming it’s based on distance.
As Keith stated, that’s why the done variable exists. Since the events run sequentially, the variable is set to false before checking what value the aggro is at, then each check on the aggro also checks if that variable is false. If both conditions are met, then the event runs, and the variable is set to true so that no other event in that group runs.
I didn’t include the aggro setting code bc 1) as a new user I can only upload one file per post, 2) it is separate from the behavior setting code, and 3) I know the aggro itself works because I have a bar for each dino that displays the aggro and works fine. However, here’s part of the aggro code for reference:
Funny story: The reason the objects weren’t moving wasn’t because of any bug in the code, but rather because I had set the objects to move within set coordinates, then moved the map so that the coordinates each object was using were misaligned and outside of anywhere they were able to pathfind to. I only figured this out after removing everything that would have blocked their pathfinding (for other unrelated reasons), and saw them navigating towards the old coordinates. I have since updated the coordinates to match the current map, and everything works now. Thank you for your help.