• 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!

GameMaker Problems with Melee Attack after killing enemy and enemy (2)

G#m_Player2

Member
Hello GameMaker Community, I recently have a problem in my melee attacks. I watched Shaun spalding's melee attack tutorial together with my other knowledge with his other videos about attacking enemies and parent objects but I may still have a lack of coding knowledge and I want to learn more hopefully you can provide the help that I needed :). I have 2 problems about the process after which the player finishes melee attacking the enemy:
[1] First is the sense of direction which where my last melee attack is used. Example is when I kill the enemy from the left side, the "oEnemyD" (stands for obj_enemydead) will be sent flying to the right side instead. Which I expect the oEnemyD should be flying to the side from where it was attacked.
1.PNG

2.PNG



[2] Second is my other object "oEnemy2" when killed by the oPlayer it spawns the same instance as the first "oEnemy"3.PNG4.PNG

I am using the script of Shaun Spalding's Melee attack tutorial:
------------PlayerState_MeleeAttack1();-----------

GML:
hsp = 0;
vsp = 2;

//Start of attack
if(sprite_index != sPlayerA)
{
    image_index = 0;
    image_speed = 2;
    sprite_index = sPlayerA
    ds_list_clear(hitByAttack);
}
//Use attack hitbox & check for hits
mask_index = sPlayerA_HB;
var hitByAttackNow = ds_list_create();
var hits = instance_place_list(x,y,oEnemy,hitByAttackNow,false);
if(hits > 0)
{
    for(var i = 0; i < hits; i++)
    {
        //if hits instance has not yet been hit by this attack
        var hitID = hitByAttackNow[| i];
        if (ds_list_find_index(hitByAttack,hitID) == -1)
        {
            ds_list_add(hitByAttack,hitID);
            with (hitID)
            {
                EnemyHit(2);
            }
        }
    }
}
ds_list_destroy(hitByAttackNow);
mask_index = sPlayer;

if(animation_end())
{
    sprite_index = sPlayer;
    state = PLAYERSTATE.FREE;
}
and EnemyHit(); script:

GML:
var _damage = argument0;


hp -= _damage;
flash = true;
if(hp <= 0)
{
    with (instance_create_layer(x,y,layer,oEnemyD))
    {
        if (other.image_xscale == 1) direction = 0;
        else direction = 180;
    }
    instance_destroy();
}
If you need anymore script or event that can help you understand my problem I am happy to assist you. I hope someone can help :)
 

Roleybob

Member
Can't tell from the details given - are you actully using image_xscale to flip the image when facing left? If you are using a different method and never update image_xscale then it will always equal 1;

You haven't provided the code which spawns the new enemy
 
The problem is with this line in the script:
Code:
 with (instance_create_layer(x,y,layer,oEnemyD))
The script is being called from within a with() statement already, so when you use other inside of the with() statement I linked above, you are not referring to the player, you are referring to the enemy being hit (as that is what with (hitID) refers to). So the dead enemy flies in whatever direction the alive enemy was facing, not in the direction the player is facing.
 
Top