How do I differentiate attacking between enemy instances?

0 favourites
  • 15 posts
From the Asset Store
Moles Attack game assets for 2D whack a mole smash and hit action fun game.
  • I am using construct 2 to make a game for a college assignment. My team of three has been extremely enthusiastic so we have gotten a lot done in the past two weeks. However I keep running into a nagging problem. I have instance variables that tell our skeletons to set their animations to attack upon hitting the players aggro box. However, even though "engaging" is an instance variable, it sends out a global command. I've just started to read about UIDs but I'm not sure how to best implement them in this case.

  • It's difficult to really tell without seeing the full capx, but why are you using separate objects for enemy and enemy aggro? If you're following the recommended practice of using a bounding box (EnemyAggro in your case) for the actions and a sprite for the animations, you need to store all of the necessary data and behaviours in the bounding box object, and only pass on the necessary animations to the animation sprite.

    From what I can tell, you're assuming that the bounding box knows which skeleton animation to trigger, and vice versa. It won't unless you specify that, so it's applying the actions to every instance. Depending on how your game is set up (or rather, you should set your game up in this way), you should be using containers to pair each skeleton to a bounding box so they always know to which instance you're referring. Read this manual entry on containers.

    Also, you have loads of redundant "every tick" conditions there. Read this very important blog post.

  • Thank you for responding, when you say by adding containers it will differentiate between my instances, will that be automatic? Or do i still need to add multiple events for each instance? When you say enemy do you mean the red sprite? That is the skeletons dummy colisor sprite

  • Do you know of a good .Capx example where this method has been used before?

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • Oh, okay in that sense your events are even more muddled than I thought

    Read through the containers manual entry for all the details, but essentially, containers make different objects behave together very well.

    If you put the red sprite, aggro sprite and skeleton animation together in one container, when you have a condition that picks any of those objects, it will always pick the corresponding other objects in the container for the purpose of actions.

  • Here's a quick example I put together to illustrate the difference between events referencing objects in containers, and those not in containers. Hopefully it'll give you a clear visualisation of what's going on inside your game.

    Also worth noting is that objects in containers are automatically created at the origin of their "parent" objects (although containers are actually flat and not in a hierarchy, they can still use root objects to create the rest of the container objects). Otherwise, if those objects already exist, they are paired according to the order in which they were placed in the layout.

  • What makes you call them muddled? They work perfectly well aside from our container issue, thank you very much I will give that a try.

  • Because the logic is wrong. The "container issue", as you call it, is at the root of the problems.

  • /

  • I tried making both the skeletons new hit box and the skeleton itself a container for the other at separate times, but the skeletons still attack in sync

  • So i'm making a hitbox for the skeleton, making it a container and then creating multiple instances of it which should each react independently? Excuse me if i am slow on the uptake, my brain is frazzeled

  • I suggest that you take a step back, learn and understand fundamentally how picking and events work and how containers and/or families will help. Then try to rework your game logic using that knowledge. There's little point in throwing a bunch of new ideas at wonky code unless you understand those ideas.

  • use System: For Each (object name) on your events.

    and you could identify which enemy is partnered with which enemy box (or vice versa) by using this method:

    pin the enemy to the enemybox, then you can use the condition "Pick by evaluation"

    For example:

    +EnemyBox: Life > 0

    +For Each EnemyBox

    -> your actions

    -(Sub event) Pick Enemy where EnemyBoxUID = Enemy.pin.pinnedUID

    -> your actions

    Pick Enemy where EnemyBoxUID = Enemy.pin.pinnedUID

    means that you pick the enemy object that is pinned to the specific instance of the enemybox object

    you can use it the other way

    Pick EnemyBox where EnemyBoxUID = Enemy.pin.pinnedUID

    means that you pick the enemybox object that you pinned the specific instance of the enemy object to

    Read more about both concepts first on the manual to understand it better before attempting to use it.

    as for reacting independently, you have to use random to randomize the AI. of course use "For Each" in the events.

    reply with my name if you need a capx sample.

  • Try to add "for each skeleton" as an upper condition. Then put every other condition under it. I am not sure which event needs it but I'm almost sure this is the case.

    Hope it helps.

  • Thank you GeometriX, I took your advice and ran back through how events work and thanks to that i managed to muddle my way through this problem! Thank you all for sparing the time to help me with my problem

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