Make node move away from another node?

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

I’m making an enemy ai who chases the player, but when they get stuck on an object, like a rock I want them to move away from it a little so they can continue chasing.

This is how I move towards my target

$Raycast.cast_to = (Target.global_position - global_position)
$Raycast.force_raycast_update() 
DIR = $Raycast.cast_to.normalized()
var motion = DIR * SPEED
move_and_slide(motion)	

so how do you move a point away from another point, I have no idea, thanks

:bust_in_silhouette: Reply From: sash-rc

Basically “AWAY” is a reversed vector, i.e. negated.

DIR = -DIR

However, you don’t need to “move away”, you need to detour obstacles. For this you need to employ pathfinding with Navigation.

Oh wow so simple xD thanks. Also with pathfinding do you need to have a tileset? because I don’t have one yet, that’s why I chose to use this tutorial A Bit Awake - News
because it didn’t rely on having a set tileset.

MasterRN | 2021-07-19 16:22

with pathfinding do you need to have a tileset?

No, it is independent from tiles.

There’s a official demo project asset: 2D Navigation Demo - Godot Asset Library
Google for tutorials, even for 3D, they are very similar of its 2D counterpart.

sash-rc | 2021-07-19 16:45

Thanks this is a big help

MasterRN | 2021-07-19 17:59