Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
This post has been wikified, any user with enough reputation can edit it.
avatar image
0
Question by L0932 · Aug 13, 2013 at 10:06 PM · movementspace shooterspace invaders

Better way to check for enemies on the left/right side of "array"

Hi, I am making a space shooter similar to space invaders. Currently, the enemies are parented to a single game object, which moves with a script called EnemySpawn.js. At the moment , the script checks for enemies that are still alive that are located to the farthest left and for enemies that are on the farthest right of the array. If the enemies on either side pass the screen boundaries, the entire game object "bounces" back.

Currently, I have the script set to check for only the top row of enemies that are on the farthest right/or left. This is because enemies in the top row are usually the last remaining enemies after all the enemies below them have been killed. However, in rare cases the top enemy gets killed before the one below it, and the script incorrectly checks if the next enemy in the top row will pass the boundary, causing the enemy in the bottom to temporarily dissapear out of view once the top enemy reaches the boundary.

what is the most efficient way of doing the check so that enemies in the farthest left or farthest right correctly bounce the entire enemy array around, without causing enemy on the farthest side to temporarily dissapear?

Comment
Add comment
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

1 Reply

· Add your reply
  • Sort: 
avatar image
1
Best Answer

Answer by Joyrider · Aug 13, 2013 at 11:09 PM

I doubt it is the most efficient But one idea could be to use a 1 line int array holding the number of enemies per column.

[3][3][3][3][3][3][3]

.X .X .X .X .X .X .X

.X .X .X .X .X .X .X

.X .X .X .X .X .X .X

Everytime an enemy dies, the dying enemy substracts 1 from his column's enemy count.

[3][3][3][3][3][3][2]

.X .X .X .X .X .X .X

.X .X .X .X .X .X .X

.X .X .X .X .X .X

and so on until you get the situation you're talking about

[1][0][2][0][2][3][0]

.. .. .X .. .X .X ..

.X .. .X .. .X .X ..

.. .. .. .. .. .X ..

And this way you still just have to check on line ;)

Comment
Add comment · Show 3 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image L0932 · Aug 14, 2013 at 07:26 PM 0
Share

That's a wonderful answer. Thanks for your input

avatar image Jamora · Aug 14, 2013 at 07:33 PM 0
Share

L0932, if this answer helped you, mark it as the correct answer ( the checkmark below the thumbs). +1 from me for the ASCII pictures (the solution is elegant too...) =)

avatar image L0932 · Aug 15, 2013 at 01:46 AM 0
Share

I have solved my problem, but I will set your response as the correct answer because it's the most informative. If I had more reputation I would also up vote it

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

17 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

The referenced script on this behavior is missing! 2 Answers

Making a bubble level (not a game but work tool) 1 Answer

How would I go About making a flying player move forward, but also Around another object? 0 Answers

Scripting errors I don't know how to fix! Can anyone help? 1 Answer

How can I make the Unity Standard Asset plane move in a scripted manner? 1 Answer


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges