• Hey Guest! Ever feel like entering a Game Jam, but the time limit is always too much pressure? We get it... You lead a hectic life and dedicating 3 whole days to make a game just doesn't work for you! So, why not enter the GMC SLOW JAM? Take your time! Kick back and make your game over 4 months! Interested? Then just click here!

Help with Beat'em up enemy

G

GiovanniT

Guest
Hello, I have been trying my hand at building a small beat'em up style game much like Double Dragons for the NES. I am currently having trouble with the enemy movement.

I have the code currently set up as follows

//check left or right
if o_player1.x > self.x and
//checking if within radius to follow
distance_to_object(o_player1)<=150
and
//check radius, too close to stop
distance_to_object(o_player1)>=6 {

move_towards_point(o_player1.x+23,o_player1.y,4)
}
else
speed =0

The problem I am encountering is the enemy will move towards the player, but it wont move to the exact position. If I move the player up or down, the enemy will try to move back but then fall just short sitting right above or right under the player while trying to execute the attack. I added a screenshot, though I dont know how much that will help.

As the first one did not work I then tried removing the close distance check

if o_player1.x < self.x
and distance_to_object(o_player1)<=150{
//move towards the player at set speed
move_towards_point(o_player1.x+23,o_player1.y,4)
} else speed=0

with this one the enemy did move to the exact point as I needed it to but once it reached that point it started shaking back and forth like it was stuck, while still executing the attacks, bypassing the 0 speed check?


I also tried creating a


can attack check

Create:
can_move=false
can_attack=false

Step Event:

If distance_to_object(o_player1) <=150 and distance_to_object(o_player1) >=6{
can_move=true
}
else
if distance_to_object(o_player1) <=5{
can_attack=true
can_move=false
}

if can_move=true{
move_towards_point(o_player1.x+23,o_player1.y,4)
} else speed=0



This bit of coding did not work for me either, it appeared to be a mixture of problems from the first and second.
 

Attachments

M. Idrees

Member
Use this code
Code:
if instance_exists(o_player1)
{
   if ( point_distance(x,y,o_player1.x,o_player1.y) <= 5 )
    {
        speed = 0;
        // Attacking sprite here <-----
    }
    else
    if ( point_distance(x,y,o_player1.x,o_player1.y) <= 150 )
    {
        move_towards_point(o_player1.x,o_player1.y,0.5)
        // Enemy walking sprite here <--------
    }
    else
    {
        speed = 0;
    // Enemy Idle sprite here <-----
    }
                    //-------------------\\
    // Set The image_xscale
    if ( o_player1.x < x )
    {
        image_xscale = -1;
    }
    else
    {
        image_xscale = 1;
    }   
}
 
Last edited:
G

GiovanniT

Guest
eeeeep ty sooo much, I am going to try and implement this coding now and see how it works for me. Thank you again :D
 
Top