+1 vote

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

Godot version 3
in Engine by (27 points)

1 Answer

+1 vote
Best answer

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.

by (1,438 points)
selected by

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 https://abitawake.com/news/articles/enemy-ai-chasing-a-player-without-navigation2d-or-a-star-pathfinding
because it didn't rely on having a set tileset.

with pathfinding do you need to have a tileset?

No, it is independent from tiles.

There's a official demo project asset: https://godotengine.org/asset-library/asset/117
Google for tutorials, even for 3D, they are very similar of its 2D counterpart.

Thanks this is a big help

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 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 webmaster@godotengine.org with your username.