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

SOLVED I have a problem with the collision event (problem was collision mask)

H

hisoka_2020

Guest
This is my first time in years asking for help. so I hope someone out there could help me.


here's an explanation of my problem:

I'm making a mini RPG game and i have a new enemy that follows his comrades around and heals them.
For some reason the new enemy doesn't seem at all to respond to the collision events.
Not for the walls, he just passes strait through them.
Not for the bullet that the player shoots, he's just ignores it.


The main thing I thought causing the problem was that he's running a for() command in his step event, so I thought the computer (not so great) might not be as functional as first seemed.
But further experimentation proved that it's not the computer's fault


Here are the things I've tried to do in order to fix said problem:

-Reinstall game maker.
-Copy the healer and the bullet and destroy the previous ones.
-I've tried putting the piece of code in both the healer and the bullet.
-I've tried changing the collision event of the healer with the wall to say instance_destroy() (he's definitely touches the wall, and he's definitely not destroying itself).
-I've tried changing the collision event of the bullet with the healer to say instance_destroy() (they're definitely passing through each other).
-I've tried creating a new independent object and told it to get destroyed when ever it comes to contact with the healer (doesn't work).


Here's the code pieces:

THE BULLET:
Collision with wall:
instance_destroy()

Collision with the healer:
if(other.side != side)
{
other.life -= 1
instance_destroy()
}
(side refers to if their an enemy or a friend, side = 0 -> friend, side = 1 -> enemy)

THE HEALER:
Collision with wall:
speed = 0

NOTE: The bullet is in fact on side = 0 and the healer is in fact on side = 1


Thanks!
 
Last edited:

TheouAegis

Member
Post the healer's movement code. It doesn't matter if the healer stops upon collision if the healer is then told to move again after the collision. You're also not moving the healer outside of the wall collision, so he's just going to stop in the wall, move again, stop in the wall, move again, stop in the wall, move again... You need to put the healer outside the wall after it collides with the wall.
 
H

hisoka_2020

Guest
GML:
if(instance_number(enemy_father)>0)
{
        for(i=0; i<instance_number(basic_enemy); i+=1)
        {
            new = instance_find(basic_enemy,i)
            if(i == 0)
            {
                lowest = new
            }
            else
            if(new.life<lowest.life)
            {
                lowest = new
            }
    }
    chase = lowest
    direction = point_direction(x,y,chase.x,chase.y)
    if(abs(chase.x-x)<64 and abs(chase.y-y)<64)
    {
        speed = 0
    }
    else
    {
        speed = 8
    }
}

This code does the following:
It asks if the number of enemies is larger than zero.
Then, if true, it runs a for() which checks all of the enemies lives and puts the id of the one with the lowest lives in the variable "lowest"
after that, it tells the healer to head in the direction of said enemy, then tells him that if the enemy (which he's chasing) is close enough then stop moving.
The actual healing action is in the enemy's code.

I just want to say that in this example of code it indecates that the healer will not stop, BUT! I did try to put in the collision event the following code:
instance_destroy()
So even if he doesn't stop,he'll still be destroyed (which, by my reaction you could guess, doesn't happen).
 
Last edited:
H

hisoka_2020

Guest
basic_enemy is the first enemy in the game. What he does is simple:
Follows you around and shoots at you little bullets.
The enemy_father, as the name suggests, is home for all of the enemy's shared code, (for example drawing the life bar) using the parent and child system.
 
H

hisoka_2020

Guest
I noticed that problem as I wrote the previous message, the problem was what you described, in the very first if(), it needed to ask: if(instance_number(basic_enemy) > 0)
Because if there are no more enemies left beside of himself, then he wont be able to move.
I fixed it now, but it wasn't what caused the problem.
 

Nidoking

Member
I notice that you're not checking for walls in the movement step when determining speed and direction. You might want to do that.
 
H

hisoka_2020

Guest
I notice that you're not checking for walls in the movement step when determining speed and direction. You might want to do that.
I don't fully know how should I do that.
But I am convinced that it the problem is with the collision event, by my example here:
I did try to put in the collision event the following code:
instance_destroy()
So even if he doesn't stop, he'll still be destroyed (which, by my reaction you could guess, doesn't happen).
 

Yal

šŸ§ *penguin noises*
GMC Elder
Does the sprite have a proper collision mask? If the mask somehow is empty, there's no pixels that can actually collide with the walls.

Make sure that the enemy is a child of enemy_father, otherwise the code it inherits won't actually be inherited (and movement / collision stuff usually goes in the parent)

If you have code in the same events as the parent, make sure you use event_inherited to run the parent's code if you want to have BOTH that and the child-specific code.
 
H

hisoka_2020

Guest
Does the sprite have a proper collision mask? If the mask somehow is empty, there's no pixels that can actually collide with the walls.
You Got The Head Shot!!!
THANKS A LOT!!
I Didn't Think That The Mask Would Be Messed Up!
Thanks!
<3 <3
 
Top