• 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 Circle [SOLVED]

I'm trying to do a point in circle collision detection. The problem is simple. I just want to see if one of my bad guys is within a circle. I tried the collision circle detection function and the point in circle and there must be something I'm not doing because its not picking up the collision on either way.
Code:
var _x = x;
var _y = y;
Code:
with(BigBrainObject)
{
    if (point_in_circle(x, y, _x, _y, 600))
    {
        inst4 = BigBrainObject
    }
}

if (inst4 != noone)
{
with (inst4)
{
floater = instance_create_depth(x+10, y-10, -1700, DamageIndicatorObject);
//hp_minus = irandom_range(5, 20);
//hp_minus = irandom_range(1,5);
hp_minus = irandom_range(1,5)
floater.text = string(hp_minus);
hp = hp - hp_minus;

hp -= 200;
}}

Should be simple, right?
 
C

Catastrophe

Guest
First thing is this is a pretty easy to debug issue without outside help: Just use either show_message or show_message_debug with the x/_x's and y/_y's and it'll probably be apparent if you have some sort of user error: you're likely just not checking the collision in the right place (and you can do a simple show_message inside the point_in_circle block to see if it ever triggers)

Second thing is, there might be a scoping issue. inst4 is set to BigBrainObject, but is it var'd? If not you'll need to use other.inst4 We'd need to see more code to get a full understanding. Also, I'm assuming you want


inst4 = BigBrainObject
->
inst4 = id

since your variable is makes it seem like you just want it to be an instance and not all objects of that type.
 
Last edited by a moderator:
First thing is this is a pretty easy to debug issue without outside help: Just use either show_message or show_message_debug with the x/_x's and y/_y's and it'll probably be apparent if you have some sort of user error: you're likely just not checking the collision in the right place (and you can do a simple show_message inside the point_in_circle block to see if it ever triggers)

Second thing is, there might be a scoping issue. inst4 is set to BigBrainObject, but is it var'd? If not you'll need to use other.inst4 We'd need to see more code to get a full understanding. Also, I'm assuming you want


inst4 = BigBrainObject
->
inst4 = id

since your variable is makes it seem like you just want it to be an instance and not all objects of that type.
I don't know. Something odd is going. I am using a collision circle and when the bad guys hit the collision circle they just stop, like they ran into something.
 
Here is the code:

Code:
var _x = x;
var _y = y;
var inst4 = noone

with(SimpleBrain)
{
    if (point_in_circle(x, y, _x, _y, 300))
    {
        inst4 = SimpleBrain
    }
}

with(BigBrainObject)
{
    if (point_in_circle(x, y, _x, _y, 300))
    {
        inst4 = BigBrainObject
    }
}


with(LaserBrainObject)
{
    if (point_in_circle(x, y, _x, _y, 300))
    {
        inst4 = LaserBrainObject
    }
}

with(ScorpionBrainObject)
{
    if (point_in_circle(x, y, _x, _y, 300))
    {
        inst4 = ScorpionBrainObject
    }
}

with(DrillBrainObject)
{
    if (point_in_circle(x, y, _x, _y, 300))
    {
        inst4 = DrillBrainObject
    }
}


if (inst4 != noone)
{
with (inst4)
{
    floater = instance_create_depth(x+10, y-10, -1700, DamageIndicatorObject);
    //hp_minus = irandom_range(5, 20);
    //hp_minus = irandom_range(1,5);
    hp_minus = irandom_range(1,5)
    floater.text = string(hp_minus);
    hp = hp - hp_minus;



    hp -= 200;
    
    if (hp <= 0)
    {
        instance_create_depth(x, y, -1200, DieingBrainSound);
        with (inst4)
        {
            instance_destroy()
        }
    }
}}
 
C

Catastrophe

Guest
Well I mean, it sounds like you didn't really read my post :/ Your inst4 are still the object index and not id. And you haven't added any kind of logging (show_message inside the point_in_circle checks)

Also, saying things are stopping inside the collision is different from saying the collision doesn't work or register, kinda hard to help you if I don't even know what's wrong. There's nothing in this code that would cause enemies to stop moving either, so I think I need to see even more code. Unless they stopped because the game crashed xD In which case the error report.

Another thing is, looking at this new code, if two enemy types are inside the circle, only one will register with this collision. You don't want to do something like this inside of one object, you want to give your enemies a parent object and then in that parent object check your collision against whatever is causing this circle effect.

Typically you also wouldn't bother using point_in_circle, a more clear but identical option is generally checking if point_distance (x,y,x1,y1) < radius.

Also, your code has a with (inst4) block inside of the with (inst4) block which is uneccessary. Simply call instance_destroy()
 
Last edited by a moderator:

samspade

Member
Here is the code:

Code:
var _x = x;
var _y = y;
var inst4 = noone

with(SimpleBrain)
{
    if (point_in_circle(x, y, _x, _y, 300))
    {
        inst4 = SimpleBrain
    }
}

with(BigBrainObject)
{
    if (point_in_circle(x, y, _x, _y, 300))
    {
        inst4 = BigBrainObject
    }
}


with(LaserBrainObject)
{
    if (point_in_circle(x, y, _x, _y, 300))
    {
        inst4 = LaserBrainObject
    }
}

with(ScorpionBrainObject)
{
    if (point_in_circle(x, y, _x, _y, 300))
    {
        inst4 = ScorpionBrainObject
    }
}

with(DrillBrainObject)
{
    if (point_in_circle(x, y, _x, _y, 300))
    {
        inst4 = DrillBrainObject
    }
}


if (inst4 != noone)
{
with (inst4)
{
    floater = instance_create_depth(x+10, y-10, -1700, DamageIndicatorObject);
    //hp_minus = irandom_range(5, 20);
    //hp_minus = irandom_range(1,5);
    hp_minus = irandom_range(1,5)
    floater.text = string(hp_minus);
    hp = hp - hp_minus;



    hp -= 200;
   
    if (hp <= 0)
    {
        instance_create_depth(x, y, -1200, DieingBrainSound);
        with (inst4)
        {
            instance_destroy()
        }
    }
}}
Adding to Catastrophe's comments (I agree nothing in this code would stop anything from moving so if that's the issue, this code isn't the problem) that use of with isn't going to work well. There's a couple issues with it. First, if there is more than one of any of those objects it will keep looping within the loop and resetting inst4. Second, it will set inst4 for each one after it. So at best it will only work for the last isnt4 assigned not all of them. You could simply all of this code to the following as well:

Code:
with (parent) {
    if (point_in_circle(x, y, _x, _y, 300))
    {
        floater = instance_create_depth(x+10, y-10, -1700, DamageIndicatorObject);
        //hp_minus = irandom_range(5, 20);
        //hp_minus = irandom_range(1,5);
        hp_minus = irandom_range(1,5)
        floater.text = string(hp_minus);
        hp = hp - hp_minus;

        hp -= 200;
   
        if (hp <= 0)
        {
            instance_create_depth(x, y, -1200, DieingBrainSound);
            instance_destroy()
        }
    }
}
Where parent is the parent of all the other objects. Alternatively, you could turn the part inside the if statement into a script and just call the script instead of setting inst.
 
Top