Attention | Topic was automatically imported from the old Question2Answer platform. | |
Asked By | rabbitslime |
I am trying to make an isometric game with AI that path-finds its way to its food source. Right now, the path-finding algorithm is not working. The AI is the blue sphere with 7 dark blue stumps for feet, it moves similar to a wheel. Its food source is the red one, but the image is just a placeholder.
This is the nav mesh collision, I only placed the collision on the green part of the 1st tile as its the only one the entity can step on. Its cut around the corners to prevent the entity from stepping on one edge of a tile to the other. The other tiles are meant to be obstacles.
This is the script
extends KinematicBody2D
var speed = 150
onready var nav = get_parent().get_node("Nav")
var path = []
onready var goal = get_parent().get_node("RedGhola").get_global_position()
func _ready():
set_physics_process(true)
update_path()
func update_path():
path = nav.get_simple_path(get_position(),goal,false)
func _physics_process(delta):
if path.size() > 1:
var d = get_position().distance_to(path[0])
if d > 2:
set_global_position(get_global_position().linear_interpolate(path[0], (speed*delta)/d))
else:
path.remove(0)
The ‘get_simple_path’ returns null.
I am not planning on using the Astar method as the map can get big, really big, like a 40 by 40, and the entity should not find food from one side to another, it should only find it a maximum of 8 tiles. If however it cannot find food, it will move randomly in one of the 4 directions. I started in Godot for a week and am a fresh IT graduate (2 months).