GMS 2 Collision Event + place_meeting [SOLVED]

Hello everyone!

The problem I have faced with is more or less common, but I didn't find any solutions for my case.

I create bullet object and it has a speed. As far as I know, the speed determines the distance in pixels where object would be drown every step. So if the bullet has speed 6, and there is an object in front of it which width is less than 6 pixels, the collision may not be registered, because depending on it's start position bullet may not appear inside of the object and not interact with it.

The second reason why I want to determine collisions precisely is that I don't like decals to be drawn inside of the object bullet interacts with. And every time (depending on start position) collision occurs at different depth. That is how 'Collision Event' works. But I want to register collisions right at the edge of the object.

I use the popular script for this purpose inside bullet's step event:
Code:
//Horizontal Collision
if (place_meeting(x+hspeed,y,obj_wall))
{
    while(!place_meeting(x,y,obj_wall))
    {
        x += sign(hspeed);
    }
    hspeed = 0;
}
x += hspeed;

//Vertical Collision
if (place_meeting(x,y,obj_wall))
{
    while(!place_meeting(x,y+sign(vspeed),obj_wall))
    {
        y += sign(vspeed);
    }
    vspeed = 0;
}
y += vspeed;
It works nice. Decals are drawn exactly at the edge of the wall or crate or any other object.

Now I want to use Collision Event inside of object bullet collides with to provide damage script, destroy animation and so on. And guess what? Collision event didn't work. I found that Collision event doesn't detect COLLISION but OVERLAPPING. Which means I need to change my place_meeting script so it provides overlapping. But I don't know how. I've tried to add something like x += 1; after place_meeting returned true, but it's still not working. Decals animation plays deeper in object, so the bullet actually moves inside of it, but the collision event is still not working.

Is anybody aware of this issue?

UPD: The picture as a quick issue guide
 
Last edited:

marasovec

Member
In programming world collision happends when 2 or more instances overlaps.
To make the wall's collision event work just replace
Code:
while(!place_meeting(x+sign(hspd),y,obj_wall))
to
while(!place_meeting(x,y,obj_wall))
so the bullet will be one pixel in the wall and triggers the wall's collision event
 

Bentley

Member
If you want the collision event to perform when there's no collision, you can (I think) use event_perform.

If you want the explosion to appear inside the wall that was "hit", you can offset where you create it: x += irandom_range(something, something);

Unless my bullets are very fast and the walls/enemies are very skinny, I just move the bullets "move_speed" per step. The collision event with walls will perform, and the bullet goes inside the wall up to "move_speed - 1", so you can create the explosion where the bullet is inside the wall.

Just some ideas.
 
In programming world collision happends when 2 or more instances overlaps.
To make the wall's collision event work just replace
Code:
while(!place_meeting(x+sign(hspd),y,obj_wall))
to
while(!place_meeting(x,y,obj_wall))
so the bullet will be one pixel in the wall and triggers the wall's collision event
I'm pretty sure I tried this and got no effect. Code in The Collision Event didn't work.
 
I've found the problem. It was instance_destroy(); function right after plaece_meeting script. As soon as I moved it into Collision event:
Code:
with(other){
   instance_destroy();
}
everything went fine. Collisions detect perfectly.
 
Top