+1 vote

I made a script for the player to walk towards the enemy's position, the problem is I don't know how to determine the position so that the player can stop outside the enemy's radius

The script that I made always makes the player stop right at the enemy's position point. The temporary solution I have is to detect the enemy radius with area2d, but that's not good

enter image description here

Godot version 3.4.2
in Engine by (73 points)

1 Answer

0 votes
func example():
  var enemy = $enemy.global_position
  if $player.position.distance_to(enemy) < 3:
      print("bla bla")

Note : Number 3 ( three ) . Try changing

I have a question for you too. How did you add that image here? I couldn't find where to add

by (755 points)
edited by

Put the image link (eg from: imgbb.com) that you have uploaded in the green box in the image

enter image description here

Thank you, so we can't add from PC, right?
By the way, did you solve the problem?

btw thanks for the answer, can you tell me how can i find out the position of the vector outside that radius?

enter image description here

No, you can't upload directly :)

Does the enemy have a Collisionshape?

func example():
  var enemy = $enemy.global_position
  #Let's say there is.
  #I assume you have a field
  var enemy2 = $Enemy/Area2D/CollisionShape2D.shape.radius
  if $player.position.distance_to(enemy) < enemy2:
          print("bla bla")


Wah great idea, I should have added a collisionShape. thanks

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.