So my racing game bot’s system works by checking if each node has the right order number, and then it moves to that node based on its ID. The problem is, this only lets me create one path for the bot to follow.
To fix this, I tried changing it so that the bot checks the node’s ID like before, and then does a ray cast to see if there’s a clear path to the node. If there are no obstacles in the way, the bot moves to that node.
But here’s the thing - this solution is causing my game to freeze up!
Here is my implementation:
I haven’t recreated or thoroughly examined your events but, by looking at the code I think it is not supposed to be running every frame but rather once by using Trigger once. This might be the issue of why it crashes so quickly, as too much stuff is going on in the background. Running a profiler test should let you know which area of the code is taking the most.
You can also try slowly going trough the code by disabling the parts until you get to the area of where the code fails , this is done by pressing D on the condition.
Lastly you can also search for your variables in the debugger , I assume it might be a while loop problem of some of your variables responsible to end the loop not updating.
I’m assuming the foundNode variable is never being set to true. FYI, wait events don’t elapse within a loop like a while event because the time is checked between frames and the while event is keeping execution within the same events. I’m guessing the events after the wait never get triggered. Try it without the wait.
Will there always be a valid node. If not, you might need a different strategy to prevent being stuck inside an infinite loop. Honestly, I don’t like the while event bc of the possibility for infinite loops.
As is, it looks like it’s stuck in a loop and keeps adding a wait as quick as it can cycle. That would be a lot of waits that can’t be processed.
This while loop is in a repeat for each bot loop. Using Trigger Once DOESN’T HELP, it still freezes. I tried putting trigger once on every condition in the while loop.
The profiler doesn’t respond when the game freezes
The raycast in the while loop is the cause.
I tried without the wait. The same exact result.
Do you have any other ways to do what I am trying to achieve? I have no other idea.
I tried doing a run without the ray cast, and it worked, but without the ray cast, it can’t identify if the node is reachable.
I’m exhausted, It doesn’t lag, but the AI keeps rotating.
I removed found node thing and made it do that every frame and then rotate to it.
My implementation:
Folks, just a reminder that putting [Not Solved]/[Unsolved] or any other combination is unnecessary and is likely to lead to less responses, not more, due to people scrolling through titles quickly. If you have something marked as solved but it ends up unresolved, just remove the solved tag, please.
I’ve removed it from the title here to avoid potential issues.
You are picking a random node, then checking if it’s ID number matches the AI’s node id. This could be why it’s freezing, especially if it doesn’t match the node number repeatedly.
It should be the other way around - find nodes with matching IDs first, then pick a random one (or one closest) out of that filtered list…
Yeah, yeah I know you requested no more responses, but I think there’s one more thing you need to be aware of. This raycast:
will only succeed if it hits a Collision object. If it doesn’t, then the condition is false, and the event’s actions and subevents are not processed. AIX and AIY are the point of the raycast intersection with the first Collision object.
So your first subevent that checks the values of AIX and AIY should be on the same level as the raycast event.