How to make Enemy follow the player

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

I have 2 questions -

  1. I have this player and a enemy I want to make my enemy follow this player…

  2. Also I have my player’s gravity like → velocity.y += gravity * delta
    where var velocity = Vector2() and var gravity =3000.0
    When I print my “player.globalposition” the y position keeps on increasing.
    This creates a problem.If I have enemy’s gun and in the enemy gun script I put look_at(player.globalpostion) it does work in X axis but as the y is increasing the enemy gun points downwards…

Pls help I am kind of new…

I am pretty sure that means your player is falling

ArthurER | 2020-09-30 09:01

Yeah my player is still falling even if it’s stopped so any suggestions?

RRocky123 | 2020-09-30 09:03

hard to give an informed suggestion because there is not enough information posted to do much other than guess. people will need more information to help you , the people on this site that have enough experience to help will want to see script and the scene tree for the player and the scene the player is instanced in. I am not one of the experienced people on this site but based on what information you have posted your problem is not if the enemy can aim its gun that is a symptom or a different problem , your root problem is that your players y position says your player is falling , so what is it standing on that should be stopping it from falling?

ArthurER | 2020-09-30 13:49

:bust_in_silhouette: Reply From: Moldor2
  1. There’s a lot of great tutorials for how to make an enemy AI that can follow the player.

  2. When you are doing your y-velocity, check if the player is on the ground first so write your statement like this:

if !is_on_floor():
     velocity.y += gravity * delta
     velocity.y = 0.0

Wow it really worked…Thank you…

RRocky123 | 2020-10-01 10:23