0 votes

Here is the code
So im working on a shooter game and its my first one and im trying to make a ennemy that follows the player but im really struggling because instead of following the player it keeps the distance it innitially had with the player pls help

extends KinematicBody2D

var speed = 200
var motion = Vector2.ZERO
var player = null

func physicsprocess(delta):
motion = Vector2.ZERO
if player:
motion = position.directionto(player.position) * speed
motion = move

func onArea2D2bodyentered(body):
player = body

func onArea2D2bodyexited(body):
player = null

Godot version 3.4.2
in Engine by (14 points)


var velo = Vector2.ZERO

func _process(_delta):
  var target = $node_target.global_position
  var rot = (target - $point.position).normalized()
  if $point.position.distance_to(target) >= 10:
      $point.position += rot * velo

Ok so there is one thing i don"t get what do you mean by point

$point = $Player etc. ==> $node_name

1 Answer

0 votes
by (755 points)
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.