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

Collision and Ds_list bug

ashurlee

Member
Can anyone see anything glaringly wrong with this code that could be causing collision checks to not always trigger?
This code is written in the hitbox for the ability. I have tried multiple solutions such as increasing the size of the collision mask. Clearing the list on creation. Increasing the time the hitbox is on screen before destroyed, and rewriting the code in the script that created it. None seem to work.
The reason for this code, is to allow the hitbox to only damage an enemy once, instead of continuously damaging it for the entire time it is created. It is supposed to, check if the enemy has been hit, if not, add it to the list, so that when it checks again and see's it is in the list, it does nothing. For the most part this works, but there will be times where the collision check do not register.

Thanks in advance.


GML:
//CREATE
hit_list = ds_list_create();
x = obj_player.x;
y = obj_player.y;
image_angle = obj_player.image_angle;
alarm[0] =  5;

//STEP
with instance_place(x,y,obj_enemy)
    {
    if ds_list_find_index(other.hit_list,id) = -1
        {
        ds_list_add(other.hit_list,id);
        hp -= 60;
        obj_player.rift_ammo_count += 2;
        }
    }

//ALARM 0
instance_destroy();

//DESTROY
ds_list_destroy(hit_list);
 

ashurlee

Member
Ok, so the act of writing my problem out sparked an idea that now seems obvious.
So to anyone who has this same problem the solution appears to be as follows.

I rewrote the step event code to the code below, and put it in a collision event instead.


GML:
//COLLISION WITH OBJ_ENEMY

if ds_list_find_index(hit_list,other.id) = -1
    {
    ds_list_add(hit_list,other.id);
    other.hp -= 60;
    obj_player.rift_ammo_count += 2;
    }
 

Ommn

Member
try this:

GML:
//STEP
var _inst = instance_place(x,y,obj_enemy)
if _inst != noone
    {
    if ds_list_find_index(hit_list,_inst) = -1
        {
        ds_list_add(hit_list,_inst);
        _inst.hp -= 60;
        obj_player.rift_ammo_count += 2;
        }
    }
 

ashurlee

Member
try this:

GML:
//STEP
var _inst = instance_place(x,y,obj_enemy)
if _inst != noone
    {
    if ds_list_find_index(hit_list,_inst) = -1
        {
        ds_list_add(hit_list,_inst);
        _inst.hp -= 60;
        obj_player.rift_ammo_count += 2;
        }
    }
I ended up solving my own problem not even half an hour after posting. It turns out putting collision code in the collision event is very much advisable :')
But thanks for the responce!
 
Top