Legacy GM Collision shape comparison[solved]

W

Wild_West

Guest
Is there any way to compare when one collision circle is in contact with another? I think it's the fix I need for my attacking setup if it's possible but I wouldn't know how to express it since last time I tried assigning collision shapes to a variable and checking if that var was true it didn't work.
 

RangerX

Member
You could use the "collision_" family of functions maybe?
There's a "collision_circle()" function that will detect collision in a given circular area and return an ID.
 
The GUI is useful for debugging things like collisions
Say you have a collision variable called hit in the step event of your player, it is either true or false.
Code:
if collision_circle( x1, y1, rad, obj, prec, notme )
{
hit = true
}
else
{
hit = false
}
then put a Draw GUI event in your player obj with this in the GUI code
Code:
draw_text(32,32,hit)
Then you will see either a 1 or a 0 on the screen telling you if there is a collision or not.
 
W

Wild_West

Guest
You could use the "collision_" family of functions maybe?
There's a "collision_circle()" function that will detect collision in a given circular area and return an ID.
I think I explained my question wrong, I already know about the collision functions, I'm using them in various things for my game but what I haven't tried yet and what I don't know if I can do, is check for one collision circle from one object being inside another collision circle from say an enemy object.

Like if the player has a circle around them and the enemy has a circle around them as barriers, and the 2 collision circles hit. Is there anyway to express that situation in code?
 

RangerX

Member
Of course.
In the mob, have the circle a collision mask.
With the hero, use collision_circle() to see if you collide with the mob's circle. (basically checking if both circles collide).
 
W

Wild_West

Guest
Of course.
In the mob, have the circle a collision mask.
With the hero, use collision_circle() to see if you collide with the mob's circle. (basically checking if both circles collide).
You mean just set it as a sprite mask? That's actually what was hoping to avoid.
what's the mob by the way monster obj?
 
Last edited by a moderator:

RangerX

Member
Why you didn't want the circle part of the object's mask? Its a fast and easy way to do it I gave you.
A mob is an ennemy, your ennemy/monster object.
 
W

Wild_West

Guest
Why you didn't want the circle part of the object's mask? Its a fast and easy way to do it I gave you.
A mob is an ennemy, your ennemy/monster object.
I don't get what you're saying, what circle part of the collision mask?
 

Binsk

Member
Um... bear with me here. If you are trying to check if two circles intersect then can't you just use a point distance? Since a circle is equal on all sides then a point distance can accurately tell if a point intersects the circle. Because you have two circles colliding then any time they touch at the furthest point possible then the distance will be both of their radii combined.

So if you have circle A with r = 10 and circle B with r = 5 then they will start touching when the distance between them is r_A + r_B (aka., 15) or less. This distance can be found easily with point_distance as long as you know the radius for each.
 
W

Wild_West

Guest
Um... bear with me here. If you are trying to check if two circles intersect then can't you just use a point distance? Since a circle is equal on all sides then a point distance can accurately tell if a point intersects the circle. Because you have two circles colliding then any time they touch at the furthest point possible then the distance will be both of their radii combined.

So if you have circle A with r = 10 and circle B with r = 5 then they will start touching when the distance between them is r_A + r_B (aka., 15) or less. This distance can be found easily with point_distance as long as you know the radius for each.
well it's not a FULL on intersection it's like I said if the circle represents a barrier around the enemy and the player and the player rams the enemy barrier then bounces off it, I want the collision detection to be right when the edges of the circles touch. Just without having to make a whole extra object or sprite mask for that collision as not all my enemies are the same sizes.

Actually scratch that I know what I need to do now, thanks
 
Last edited by a moderator:

samspade

Member
well it's not a FULL on intersection it's like I said if the circle represents a barrier around the enemy and the player and the player rams the enemy barrier then bounces off it, I want the collision detection to be right when the edges of the circles touch. Just without having to make a whole extra object or sprite mask for that collision as not all my enemies are the same sizes.
You might need to draw us a picture (literally) because I am also having a hard time understanding. However, With the point distance function you can set it to any number, so it you should be able to customize it to any distance, including variable distances depending upon the enemy it is checking. There's also point in circle function if for some reason point distance or the other collision functions don't work.
 
W

Wild_West

Guest
You might need to draw us a picture (literally) because I am also having a hard time understanding. However, With the point distance function you can set it to any number, so it you should be able to customize it to any distance, including variable distances depending upon the enemy it is checking. There's also point in circle function if for some reason point distance or the other collision functions don't work.
I mean it's nothing terribly complex, like I said just 2 collision circles made using collision_circle() 1 for the player one for the target enemy. layer attacks target enemy by ramming into it, and their 2 collision circles, collide, and the player bounces off the enemy. Like a homing attack but I don't want the 2 objects to actually touch until AFTER the enemy barrier is gone via this initial collision.
 

samspade

Member
I mean it's nothing terribly complex, like I said just 2 collision circles made using collision_circle() 1 for the player one for the target enemy. layer attacks target enemy by ramming into it, and their 2 collision circles, collide, and the player bounces off the enemy. Like a homing attack but I don't want the 2 objects to actually touch until AFTER the enemy barrier is gone via this initial collision.
A number of the suggestions above would work then.

Code:
///player step eent

if (instance_exists(parent_enemy)) {
    with (parent_enemy) {
        if (point_distance(x, y, other.x,  other.y) <= circle_width + other.circle_width)) {
            /* do something */
        }
    }
}
or

Code:
if (instance_exists(obj_player)) {
    if (point_in_circle(obj_player.x, obj_player.y, x, y, circle_width + obj_player.circle_width)) {
        /* do something */
    }
}
or

Code:
if (instance_exists(obj_player)) {
    if ( collision_circle(x, y, circle_width + obj_player.circle_width, obj_player, false, true)) {
        /* do something */
    }
}
And draw the respective circles in the draw event.

Or just create a circle object with a mask that you attach to the various objects. Presumably you would have some visual element of the circle anyway.
 
W

Wild_West

Guest
A number of the suggestions above would work then.

Code:
///player step eent

if (instance_exists(parent_enemy)) {
    with (parent_enemy) {
        if (point_distance(x, y, other.x,  other.y) <= circle_width + other.circle_width)) {
            /* do something */
        }
    }
}
or

Code:
if (instance_exists(obj_player)) {
    if (point_in_circle(obj_player.x, obj_player.y, x, y, circle_width + obj_player.circle_width)) {
        /* do something */
    }
}
or

Code:
if (instance_exists(obj_player)) {
    if ( collision_circle(x, y, circle_width + obj_player.circle_width, obj_player, false, true)) {
        /* do something */
    }
}
And draw the respective circles in the draw event.

Or just create a circle object with a mask that you attach to the various objects. Presumably you would have some visual element of the circle anyway.
Right, I just always struggle with this programming math type functions I don't know why. I guess I'm just more of a visual type than a numbers type. But it's setup how I want it now.
See the issue initially was that all enemies have a barrier and you can attack them by slamming into them while your barrier is active so I had the player's collision circle set to the barrier size and he'd hit the enemies and bounce off fine but I didn't want them to be destroyed until after you hit them a second time after breaking the enemy barrier, and that's what I would get just because they were in contact still after the barrier went down. I just wanted to know if using a second collision circle was a better idea for it than making an object to act as the barrier.
 

samspade

Member
Right, I just always struggle with this programming math type functions I don't know why. I guess I'm just more of a visual type than a numbers type. But it's setup how I want it now.
See the issue initially was that all enemies have a barrier and you can attack them by slamming into them while your barrier is active so I had the player's collision circle set to the barrier size and he'd hit the enemies and bounce off fine but I didn't want them to be destroyed until after you hit them a second time after breaking the enemy barrier, and that's what I would get just because they were in contact still after the barrier went down. I just wanted to know if using a second collision circle was a better idea for it than making an object to act as the barrier.
That sounds cool. I'm glad it's working now.
 
Top