Enemy with hitbox glitching when there is more of him

Not favoritedFavorited Favorited 0 favourites
  • 13 posts
From the Asset Store
Tweakable and easy to use effects for your projects.
  • Hello I was trying to make a enemy that's composed by a hitbox and a sprite for the animations, but when there isn't only one of him in the layout they struggle to work ok. I wanted to each one work idependently.

    here is the cp3 file: drive.google.com/file/d/1gt84imsdlNiDPzeYSZ8Jt9Uw0_hRQ7N-/view

    NOTE: to test the enemy, go to the W 1-5 layout and his code is on the "Enemies" event sheet on the "Treemons" group

  • Can you make a small demo or post a screenshot of the event sheet? Your project is 27MB in size and requires addons which I don't want to install.

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • Here you are:

  • Remove "trigger once" from all events and never ever use it inside of triggers, loops, and especially with objects that have multiple instances! It's the cause of all your bugs.

    Instead of "trigger once" use additional conditions, or Timer behavior. For example, in the last event on your first screenshot you can add another condition: Tween "Idle" is not playing.

    Timer is a very useful behavior for such games. For example:

    Enemy has LineOfSight to Player 
    Enemy timer "attack" is not running : Enemy start timer "attack" for 1 second
    
    Enemy On timer "attack" : Enemy spawn a bullet
    

    This is a proper alternative to "trigger once" and "wait 1 second" (which won't work correctly for multiple instances).

  • It's like this?

    Also, I forgot to tell, the hitbox has an hierarchy with the animation sprite, and the hitbox is the parent.

  • Yeah, it looks better. Although this event is still wrong:

    It will run on every tick while the conditions are true, and will create lots of delayed threads - because of "Wait 0.5s" action. So even if another event starts the "Attack" timer and set Attacking to true, those delayed threads will reset Attacking variable back to false for half a second.

    Avoid using Wait action in non-triggered conditions.

  • It's working slightly better, but you didn't understood. They were glitching when there were multiple instances, and I wanted to them work independently from each other. Also, they are composed of hitbox and animation sprites, and how they work is basically: When you get close to one, it reveals itself and starts chasing you. When you get closer, it jumps on your direction to attack.

  • My advice still stands - never use "trigger once" with multiple instances. Don't use "Wait" action in events that run on every tick. These are very common mistakes.

    What exactly is the problem now?

  • When there are more than 1 instances of both the hitbox and the animator sprites (the animator is hitbox's child) they glitch on both movement and animations.

  • What do you mean by glitch? Moving in wrong direction? Moving at wrong speed? Not moving at all? Playing wrong animation? Not playing any animation? You need to explain the issue in detail if you want people to help you!

  • It can't show up the right animations and can't chase or attack the player.

  • Ok, I see in your screenshots that you are not picking child animator sprite. You need to add "BushMohHitbox pick children BushMohSprite" to all relevant events.

    Another option is to add these two objects to hierarchy a container. Then BushMohSprite will be created automatically for every hitbox (you don't need to spawn it), but you can still add it as a child. And it will be picked automatically in all events.

  • Oh, so that's it! Thanks a lot!

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