Can we add some algorithm on player/npc movement?

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By c21james

Can we add some algorithm on player/npc movement?

The game is just simple rpg game. But, I want to add some algorithm (like especially floyd-warshall, A-star, etc), so the player/npc can move faster toward to each others. If we can, please guide me. Thanks :slight_smile:

:bust_in_silhouette: Reply From: Eric Ellingson

You should probably look at the Navigation2D (or Navigation for 3D games) node.

( Navigation — Godot Engine (3.1) documentation in English for 3D )

I just want to add some path finding algorithm on my code, so they move faster and efficiently for my 2D game

but somehow I got stuck

var destination = Vector2()
var gap = Vector2()
var speed = null

func _ready():
 speed = 100
 destination = Vector2(position)
 
func _process(delta):
 if position != destination:
  gap = Vector2(destination - position)
  move_and_slide(gap.normalized() * speed)
  if gap.abs() < Vector2(1,1):
   set_position(destination)
 if destination == position:
  move_and_slide(gap*0)
 pass
func _input(event):
 if Input.is_action_pressed("ui_click"):
  destination = get_global_mouse_position()

c21james | 2019-08-25 12:33