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

GameMaker Execute code on 2 instances simultaneously?

B

Boogery Boogers

Guest
Hello!

I wonder if someone can help clear something up for me. So, here's what I'm trying to do:

I want players to be able to push one another slightly as they walk into each other. each instance has a basic move left/right, and when they collide they push each other back a little in the opposite direction (say for example, with 'instance_place(x,y, enemy_object) x -= "push back value" * image_xscale;').

After some digging around, I believe the order that the instances execute their code is dependent on the order the object is in the resource tree, and the instance order. so which ever instance is older/higher up in the resource tree always gets pushed back first, right?

What I wanna know is, is there a way to make this push back happen for both instances simultaneously without using the "with" statement?

Thanks
 

Attachments

zATARA_0

Member
why not using the "with" statement? Are they not the same object_type? When they collide you can check the colliding objects and "push" both back then.
 

NightFrost

Member
When one of them moves and detects a collision, you give both of them some knockback. It doesn't matter which one is the first to act, you just need one of them to realize there's a collision and send both participants flying backwards. If there's more than two characters, you'll have to decide how characters should behave when they are getting multiple knockbacks in short timeframe (getting another KB while still executing previous one) potentially from both directions.
 
B

Boogery Boogers

Guest
I would try using this, or scripts

Code:
Objectnamehere.event_perform(event here)
Thanks, I'll check that out.

why not using the "with" statement? Are they not the same object_type? When they collide you can check the colliding objects and "push" both back then.
I think the "with" statement works well for most things, but it seems fiddly when it comes to this type of scenario. For this case, they aren't the same object type. When I'm trying to get 2 moving instances of the same speeds to push each other using a "with" statement, I'm finding it's still not always perfectly equal. I assumed it was something to do with the order in the resource tree.
 
Top