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

Cool Asteroid Defense Game: Need help

F

FILMon

Guest
Hi friends,

I'm trying to create 1 new object when 3 of the same object instances collide.
Is there any simple way of doing this without having to find the instance ID and writing complex code?

Thanks in advance for any help friends :)
 

Attachments

TailBit

Member
can give them a variable that tells who they are currently hit by:
step event
Code:
hit = noone;
And in collision event it check that value of the other object, but only if it have not been detected yet, so its own hit variable need to be noone

Code:
// do not do anything if already hit
if(hit!=noone) exit;

if(other.hit == noone){
    // first time we hit anything this step
    // then let them remember eachother
    hit = other.id;
    other.hit = id;
}else{
    // you hit something that already have
    // collided, you can then use hit in
    // the other object to check if they
    // all touch
    //if place_meeting(x,y,other.hit){
        instance_destroy()
        instance_destroy(other.hit)
        instance_destroy(other.id)
        // Create instance here
    //}
}
Edit: removed place_meeting so they will destroy upon a cluster of 3
 
Last edited:

TheouAegis

Member
can give them a variable that tells who they are currently hit by:
step event
Code:
hit = noone;
And in collision event it check that value of the other object, but only if it have not been detected yet, so its own hit variable need to be noone

Code:
// do not do anything if already hit
if(hit!=noone) exit;

if(other.hit == noone){
    // first time we hit anything this step
    // then let them remember eachother
    hit = other.id;
    other.hit = id;
}else{
    // you hit something that already have
    // collided, you can then use hit in
    // the other object to check if they
    // all touch
    if place_meeting(x,y,other.hit){
        instance_destroy()
        instance_destroy(other.hit)
        instance_destroy(other.id)
        // Create instance here
    }
}
Couple issues here.

Four asteroids: A, B, C, D

A hits B, a.hit=B, B.hit=A
C hits A, A's event exits, C.hit=A, C checks B...
Outcome 1: C is colliding with B at the exact moment C initially collides with A, all is good
Outcome 2: C is not colliding with B, no more asteroid collisions can be handled by A, B, or C

A hits B
C hits D
A and B then hit C but not D, no collisions are handled

A hits C
B hits D but not A or C
D hits A and C, but code forced to exit

Setting hit for both instances kills the code anyway, but even without that, you'd still be relying on instance ordering, so even the logic lets it down.

What I would do is every step:
Code:
var inst; inst[1]=0;
var cnt=0;
with object_index if place_meeting(x,y,other.id) inst[cnt++]=id;
if cnt==2 {
    instance_create(mean(x,inst[0].x,inst[1].x), mean(y,inst[0].y,inst[1].y), new_thingy);
    instance_destroy(inst[0]);
    instance_destroy(inst[1];
    instance_destroy();
}
 
Last edited:
F

FILMon

Guest
It worked perfectly!! Thanks TheougAegis! I plan to launch the game to Mobile on Android & IOS as free to play with Ads and the option to pay to remove Ads. I promise to send you some cash once it's up and generating some income. Also, I'll keep your info in case I get stuck anywhere else. I'm almost finished with this game though :)
 
Top