0 votes

Hi guys,
I am using C# to create a game with Godot.
I am creating an enemy who has to jump a determined distance up and, once there, he has to go directly to the Player to give the Player a kick in his face. I have tried to do it, setting a Ray 2D (TheRay) in the enemy’s base and using IsColliding() to determine if the enemy is Colliding with the Floor (the tiles).
Later I use Move Toward to jump until the a point (the TopPosition) and when the Enemy has reached the TopPoint (Position.y<=TopPosition.y) I use another MoveToward to move the Enemy to the Player (to give him the kick). The problem is that the enemy
jump but doesn't have a linear trajectory to the Player but the enemy travel iterating (as a fly that is going to some food) and I don’t know why. Do you know what could be the error?
This is part of the code of the Enemy script:

public override void _PhysicsProcess(float delta)

    velocity.y += Gravity * delta;
    velocity.y += Gravity * delta;

         if(PlayerIsNear){ //the PlayerIsNear variable is a boolean that become activated with a  Signal 

            if(ThePlayer.GlobalPosition.x > this.GlobalPosition.x){
                    TheSprite.FlipH = false;
          } else{
                    TheSprite.FlipH = true;

                TheTargetPosition = ThePlayer.GlobalPosition;
                TopPosition = new Vector2(Position.x,Position.y -1000);

                Position = Position.MoveToward(TopPosition,5);


                 if(Position.y > TopPosition.y){
                    GlobalPosition =GlobalPosition.MoveToward(TopPosition,5);
                    GD.Print("it is going up");
                    if(TheTargetPosition.x > GlobalPosition.x){
                        Position = Position.MoveToward(TheTargetPosition, 5);


Godot version 3.5
in Engine by (12 points)

Please log in or register to answer this question.

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.