Problem with instances

0 favourites
  • 5 posts
From the Asset Store
For problem solving, puzzles, bubbles, platforms and other adventures.
  • Now here's probably something very basic I'm missing... It may lead to some more complicated questions so I'll post it here.

    But I'll start simple, here I'll try to explain:

    if you overlap the enemy with the crosshair and shoot (hold down z) the enemy turns red (animation frame 1), if the crosshair is not overlapping then it goes back to green (animation frame 0). This works fine if you have one enemy instance, but if you have several on screen and shoot them all they all turn red even though the crosshair is not overlapping them.

    If you don't know what I mean then I think it will become clear if you look at the capx here:

    https://dl.dropboxusercontent.com/u/98471899/Scirra/crosshair.capx

  • Here is a fixed version for you.

    [attachment=0:izo2gwhh][/attachment:izo2gwhh]

    Updated CAPX - Changed something that didn't need to change so put it back how you had it.

    Also quick explanation why yours didn't work. You were checking if the "crosshair" wasn't overlapping "enemy" but if you are aiming at any other enemy you are "overlapping" an enemy so that event wouldn't be true.

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • Thanks!

  • Here's another problem with instances...

    I tried to make some enemy ai:

    The enemy keeps going left until he comes close enough to the player; then, after a little delay, he either swings his club or he goes to the right for a short interval and then swings his club, after that it's back to going to the left looking for the player again.

    It works fine with one enemy on screen but if you add 2 more instances it messes things up somewhat.

    Maybe there's something wrong with my approach here, but I don't understand why it works with one enemy but not with many.

    https://dl.dropboxusercontent.com/u/98471899/Scirra/enemyexample.capx

  • And more... A bit clearer and better example than the last one.

    https://dl.dropboxusercontent.com/u/98471899/Scirra/StarExample.capx

    I have an enemy here going left or right and jumping at random, using the Timer behavior. With one instance it seems to able to go on forever but with two they'll get stuck after a while, may take a minute or two.

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