Enemy States Acting Weirdly

Not favoritedFavorited Favorited 0 favourites
  • 6 posts
From the Asset Store
State Machine
$10.99 USD
State Machine is a great tool for managing the state of anything in your game.
  • I've been trying to recreate Super Mario Bros. in Construct 2 for the past few months. So far progress has been going well, (albeit at a very slow pace), however I've run into a bit of a problem.

    For the life of me I cannot figure out what's wrong this code. Pretty much everything works fine, except for one thing. For context - In Super Mario Bros. when you stomp on a Koopa it goes into it's shell - everyone knows that. Here's the thing that's messing me up though, if you Jump on a Koopa when it's in its shell:

    1. the Player does not bounce off of it.

    2. The shell begins to go into its "moving" state in a random direction. (Left or right)

    I've tried a lot of things to get this right but none of them are working. Basically either 1 or 2 don't work depending on how the events are formatted. For example if I moved one one of the events up then Mario will bounce of the shell when it's standing still and it *will* move. However if I were to move them a bit further down then Mario will jump on the shell and he won't bounce off it, but it won't move either.

    I've attached my code below in case there's anything you guys can see that I can't.

  • without going too deep into it until we make some tweaks I think the main thing you are missing is an 'Else'. When you jump on the shell I think you want to do a one time check of what the state is at that point but based on your events if something else makes the status change as it is running that event you can end up with running more than one condition, so for the 4 state conditions under 'on collision with shell hitbox' you should add an Else at the top of the conditions that are meant to be an if/else type of logic so it only runs the one condition.

    When that is done, you can start to tidy up any other logic that interferes from the other events. Also adding Browser Log I find useful for debugging to check what is being run and in what order.

  • When you say add an else, do you mean something like this? Or am I misunderstanding?

  • Try Construct 3

    Develop games in your browser. Powerful, performant & highly capable.

    Try Now Construct 3 users don't see these ads
  • I'm saying for example when you collide and the shell is not moving you set it to moving, which makes the condition directly below true 'not not moving', whereas with an Else above each condition it would only run one of them.

    1. why is the player set to bounce when the shell is moving, that's what you intended? or is that a typo? Or if the player is not bouncing as you say, when is he meant to bounce?

    2. not sure on the direction as this is only set in one place and looks ok but maybe the else can tidy it up, or maybe it is a bug like when the shell goes to move state and moves past the player then it triggers the collision event again so this is why I say adding logging is good too!

  • Oooh okay I see, honestly I don't think I ever properly understood the purpose of using else statements in Construct 3 before instead of just putting the opposite of the last condition, besides to save time. but I think I kind of get it now. I added some elses and cleaned a few things up and it's working. I'll also try to get some logs implemented for bug testing like you suggested.

    Thanks for the help!

  • Nice! Yes I get what you mean, it is easy to think that it would just pick one condition but it actually runs lower down conditions if they become true before it gets there (in the same tick) so Else is important if you want an if/else type logic.

Jump to:
Active Users
There are 0 visitors browsing this topic (0 users and 0 guests)