How can I lock the pathfinding to only move my agent on 45º or 90º?
Hello everyone! I need to implement a top down 8 way movement for the enemies of my game. I could successfully implement that with the tilemap navigation layer property and navigation agent on the enemy. And it worked pretty well except for one thing. When the pathfinding aims to the next point on the chain it will point for any point of the square that represents a tile. I need that the enemy walks only on 45 or 95 degrees, it means what pathfinding can only point to the center of the next square. Is it possible using the current Godot 4.1.2 pathfinding?
#set direction to the vector to the next point.
direction = (round(direction / (PI / 4))) * (PI / 4)
#PI / 4 is for 45 degrees, PI / 2 for 90 degrees
#This is in radians, so you could have PI / 6 for 30 degree segments
velocity = (direction * SPEED).normalized()
move_and_slide()
This will round the first thing/a (in this case, direction) to the nearest multiple of the second thing/b (PI / 4). The formula is (round(a / b)) * b