This site is currently in read-only mode during migration to a new platform.
You cannot post questions, answers or comments, as they would be lost during the migration otherwise.
0 votes

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 :)

in Engine by (12 points)

1 Answer

+1 vote

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

https://docs.godotengine.org/en/3.1/classes/class_navigation2d.html
( https://docs.godotengine.org/en/3.1/classes/class_navigation.html for 3D )

by (1,663 points)

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()
Welcome to Godot Engine Q&A, where you can ask questions and receive answers from other members of the community.

Please make sure to read Frequently asked questions and How to use this Q&A? before posting your first questions.
Social login is currently unavailable. If you've previously logged in with a Facebook or GitHub account, use the I forgot my password link in the login box to set a password for your account. If you still can't access your account, send an email to [email protected] with your username.