How do I make multiples of one enemy that animate separetely

0 favourites
  • 6 posts
From the Asset Store
Be quick and choose the right answer for the shown equation.
  • Hello, I'm having an issue with creating enemies for my game, more specifically how they are animated. Since the enemies will have complex animations (running, firing their guns, standing still, etc) I created an enemy box to spawn and assign them to as I would for a player character. I gave the box the platform behavior so that it can be moved.

    (the purple 'E' box in this screenshot)

    The box has a variable called 'Direction' that controls which direction the box is facing, 'left' or 'right'. When the box collides with the GoLeft and GoRight boxes (the blue ones with arrows in the screenshot above), it turns around and goes the opposite way and sets 'Direction' to the new direction it is moving in.

    What I want to have happen is, when the box is facing left, the sprite for the enemy (the dinosaur lookin' dude in the screenshot above) attached to the box is mirrored, and when it is facing right, the sprite is not mirrored (since they face right by default).

    The trouble is that I have no idea how to accomplish that. Movement I have down pat; when I have multiple boxes they all move and correspond with the GoLeft/Right boxes properly. The sprites attached to them on the other hand, when I try to set them to be mirrored, do... er, this:

    (oh god help I'm so lost here)

    If you can't tell what's happening, the sprites are flipping around whenever ANY enemy box hits ANY GoLeft or GoRight box. Notice that the mirroring on the boxes behind the sprites is working totally fine.

    So my question is: How do I make it so that, when a box changes direction, it ONLY affects the sprite pinned to it and not the others?

  • Either use a container or use enemy is overlapping enemy box

    Another option would be assigning a variable to both enemybox and enemy, or connecting through uid with a variable..

    You have to have a way to connect the right enemy box to the right enemy..

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • Can you please provide a capx CJacobsSA? So we can see further into detail the issues here and how to fix them? Well nvm if Stains got it. Let me know if he helped!

  • Haha, wow, that was a brain fart on my end. I hadn't considered that the sprite wasn't actually connected to the box, I just figured pinning it to the box that created it would be enough! That's what I get for messing with Construct before I have my morning coffee.

    What I did to fix it was, I assigned a global variable called "EnemyID", set to 0 by default. Then I gave the box its own variable (myID_Box) as well as the sprite (myID_Enemy). Then I did the following to assign the numbers:

    And checked that the two values are equal:

    And if the value of the enemy box that hits a GoLeft/GoRight box is equal to that of an enemy sprite, the enemy sprite with the same number flips (which is, of course, true for the sprite attached to it)! Now it works perfectly! Thanks, guys!

    (Searching the tutorial section for this while troubleshooting it was a huge pain in the butt, haha)

  • Bumping my own thread because things broke immediately after I tried to add another animation. I think I'm just gonna upload the .capx so you guys can take a look at it, because I really can't explain what happens to the game in words.

    See, now I'm trying to add another animation to the variable for "action" (formerly "Direction"). When "action" is set to "shooting", the enemies stop and fire in a straight line at the player every couple of seconds, with the animation "Shoot". The problem is that everything is ten kinds of screwy with it and I'm not sure what I did wrong!

    Here is my current code for the enemy (excluding the creation). Things to ignore unless they're relevant: The direction the projectiles go in when the enemy fires & the fact that "shooting" activating doesn't take Y pos into account.

  • No time to check myself, but have you tried using containers (read the whole page: https://www.scirra.com/manual/150/containers) to associate your enemy boxes with the enemies? And then rework your whole thing with the containers in mind. I'm still a noob but just read that page and thought it could help you (and LittleStain quickly mentioned the containers already).

    Sorry if it's not actually helpful, but I think it could get you rid of the whole ID variables idea which could be causing your issues. If you're already using containers, my bad.

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