• 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 event vs place_meeting()

R

Robzoid

Guest
I'm working on a 2D platformer and am in the process of converting my player object's step event from a bunch of giant, messy if statements to a state machine. I'm trying to decide if I should leave my enemy collision event as is or remove it and replace it with this:

Code:
if place_meeting(x, y, oEnemyParent)
     state = player_state.damage;
So, in essence, I'm asking if the collision event has any advantages or differences to using place_meeting() and, if it does, which do you recommend for detecting collisions in a platformer? I'd like to keep as much of my code integrated with the switch(state) code I have in my step event. That's why I'm considering getting rid of the collision event, but I'm concerned that maybe there's something I'm not understanding that would make leaving the collision event the better approach.
 

Slyddar

Member
Even though I mostly use the collision event if applicable, if you need to control exactly when the collision takes place, in relation to the other code in the current state, then calling it like you have is appropriate. It all comes down to your preference, but you should also be aware placing it in the step might mean a state change later in the step overrides the intended damage and you miss the state change for that step.

Also congrats to moving to state machines. They are infinitely more flexible when addng features and fixing bugs.
 
R

Robzoid

Guest
Thanks for the reply. The main reason I was thinking of getting rid of the collision event is that I'm not sure exactly what impact it would have on the state machine. Since it is outside of and separate from the state machine, I was worried it would conflict with it or cause some odd behavior. I wasn't sure what the interaction between the two would be like. But it sounds like you and others use the collision event to detect enemy collisions and it doesn't cause any problems in your state machine games.

I know Yoyo isn't that clear on what order events run in, but it seems like the collision event runs after the step event. It overrides code from the state machine. That's the only way that makes sense in my mind. If the collision event ran before the step event each time, that seems like it would produce some odd behavior. Anyway, thanks for your help. I'm going to leave the collision event as is and see how this turns out.
 
D

Danei

Guest
I always handle platformer collisions manually with functions like place_meeting and instance_place, for all the reasons you both pointed out. If you find using the built-in events easier, it's quite possible that it won't cause any problems for you, but as far as I know, using the functions shouldn't have any disadvantages compared to the collision event either.
 
Top