How do I make multiples of one enemy that animate separetely

Get help using Construct 2

Post » Tue Sep 30, 2014 1:28 pm

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.

Image
(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:

Image
(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?
B
18
S
9
Posts: 103
Reputation: 1,817

Post » Tue Sep 30, 2014 1:37 pm

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..
I told my dentist I had trouble with my teeth and asked her to fix it without looking in my mouth..
B
54
S
16
G
8
Posts: 6,160
Reputation: 19,775

Post » Tue Sep 30, 2014 1:41 pm

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!
B
12
S
3
G
1
Posts: 109
Reputation: 1,979

Post » Tue Sep 30, 2014 1:53 pm

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:

Image

And checked that the two values are equal:

Image

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)
B
18
S
9
Posts: 103
Reputation: 1,817

Post » Tue Sep 30, 2014 3:27 pm

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. :lol:

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!

Image

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.
You do not have the required permissions to view the files attached to this post.
B
18
S
9
Posts: 103
Reputation: 1,817

Post » Fri Oct 10, 2014 9:21 pm

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.
B
10
S
3
G
1
Posts: 25
Reputation: 803


Return to How do I....?

Who is online

Users browsing this forum: Yahoo [Bot] and 14 guests