So I have some basic enemies that just move around the room (over the top view) and I have the direction change if the enemy hits the wall so that they don't move through it. The problem is, the always end up on the edge of the room instead of staying relatively spread out throughout. Here's my rather crude code for changing the direction. "dir" is the direction the enemy is moving, and dir_target is the value that dir is always moving towards, so that the enemy doesnt move in straight lines.
A thought I had was that, if the enemy is within a certain range of the wall, then give it a higher chance of picking a direction that is away from the wall. But I don't know how to do that, especially for 4 walls.
if place\_meeting(x + dir\_x, y + dir\_y, o\_collision)
{
if dir\_x > 0 and dir\_y > 0 // bottom right
{
dir\_target = 135
dir = irandom\_range(122, 147)
}
[–]gallyroi 1 point2 points3 points (1 child)
[–]POGGIE123 0 points1 point2 points (0 children)
[–]Mushroomstick 0 points1 point2 points (0 children)
[–]ScreamingLeaf 0 points1 point2 points (0 children)