Understand which object is more right

0 favourites
  • 6 posts
From the Asset Store
Hand-painted tiles, objects, animated objects, and background to build a colorful Mayan civilization environment.
  • Hello, here is a new beginner question.

    Just to learn im trying to recreate space invaders.

    All the enemy are copied so have the same Name. I think the best way to change direction (on collision) is to place a sprite pinned to further to the right enemy and one pinned to the further to the left enemy. When this sprite collide to the wall, all the enemy are changing their direction.

    My question is... I have a way to understand which enemy is further to the right and further to the left?

    Thanks

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • You can use an invisible helper sprite on both sides. On any enemy collide with the helper sprite, change directions for all enemies.

    Alternatively, just keep track of a set amount of "steps" to go right and left in a variable, and count it down. When it hits 0, change direction for all sprites and reset it to the original amount of steps.

  • Hi oosyrag and thanks.

    That's sound interesting but I have still one problem.

    I have all the enemy in line. When someone touch the wall should add n. to the Y of each and change direction.

    Im able to change direction (with a boolean goLeft) but im able to add n. to the Y (basically send them down) only to the enemy that touch the wall. Is there any way to have ALL the object with the same name doing the same thing?

  • I'm working on a tower defense game and i had a similar problem needed to know which of the enemy / ai that walk the path is the 1st or last... so i used the bullet behavior, set the speed to random values based on type of enemy, so some enemies are faster some are slower, and at some point if my tower shooting sprite has a target already and a speedy AI passes the 1st current target becoming the 1st target, i need to select that now since is the 1st. Bullet behavior has a "distance traveled" parameter, which counts the pixels they move around. and i used that as my distance calculation to automatically target the first AI whenever gets in front of others. but for you not sure if this is a solution it all depends on how u make the AI move, are they moving grid based? etc

    but a simple solution would be to calculate the left and right distance to the edge of the screen of the AI since that is what u need. to identify which is closest to left or right side ...

    hope it helps.

    to pick an enemy u have to run a for each loop

    and compare the distance => distance(enemy.x,0,viewportleft,0)

    which would calculate the distance of enemy ai to left side of screen or something like that. not sure if the viewportleft is correct code but u should see the proper suggestion in the event sheet if u type it in.

  • I made a little example space invaders. It's not perfect, but maybe it helps.

    https://drive.google.com/file/d/1Wokf3NvbLaFfFyMb_xiyItJDiAxl3f42/view?usp=sharing

  • GeorgeZaharia Thanks, will look into it

    Asmodean Thank you, very useful to learn from workin example!

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