• Hey! Guest! The 36th GMC Jam will take place between February 27th, 12:00 UTC - March 2nd, 12:00 UTC. Why not join in! Click here to find out more!

Legacy GM To address one of the many

mafon2

Member
Ok, I'm sure it's trivial thing many of you struggled with.

I'd like to make a block that crumbles, when contacting fallin player or special block.

Here's the code:

Code:
if (place_meeting(x,y-Movable_block.speedY,Movable_block))
{
        instance_destroy();
}
As you can see, it affects all of the Movable_blocks so it can work only with one of 'em per room. How do you adress the particular block the instance collides with?

I tried juggling with "other" with no result. I would have wrote these lines in Movable_block, but due to their common parrent that deals with collisions it's a mess I can't walk through.
 

jo-thijs

Member
Hi and welcome to the GMC!

I'm not sure which object is executing the code you just posted.
Is it Movable_block that has to "crumble"?
In that case, try:
Code:
with Movable_block
    if place_meeting(x, y + speedY, other)
        instance_destroy();
Otherwise, try:
Code:
with Movable_block
    if place_meeting(x, y + speedY, other)
        with other
            instance_destroy();
You might also be interested in reading up on instance_place.
 

mafon2

Member
Thanks for the quick replies.

The code is in obj_rubble (yeah, the names of instances lack unification). Obj_rubble should crumble if it's hit with something. For now the only things that are planned to hit it are either Player_char or Movable_block. Beforementioned code works fine with Player_char or single Movable_block, but doesn't work with multiple blocks, cause it gets speedY and position from all Movable_blocks instances.

In perfect world it should be that Movable_block falls on obj_rubble and destroys it, while other Movable_block neatly minds its own business.

I'll try the later code jo-thijs posted and report the situation.
 
Last edited:
If you want to access specific instances of objects outside of collision events, you have to capture the instance ID when using collision functions, roughly as follows:

Code:
var inst = instance_place(x, y + 1, obj_solid);

if (inst != noone)
{
    with (inst)
    {
        instance_destroy(); // This would destroy the block the calling instance is "standing" on.
    }
}
 

mafon2

Member
Jo-thijs, your solution works. Thank you.

I didn't know there're "withs". And it's hard for me to understand the rules of scripting. I thought the problem was harder than it is...

Stainedofmind, thank you too, it'll be helpful later. As I understand you suggest to use some kind of an additional "matte" to check the collision?

P.S. I used to have an account on the old forum and drove some guy to glowing frustration with my questions.
 
Top