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 MarvinH · Dec 15, 2012 at 03:17 AM · enemy aishmup

Enemy Attack CoRoutines?

Hello,

Are there any tutorials, or example codes on how to do a shoot em up style boss? See example

This is a bit of a design/code question. i have a very simple boss. I attached 2 missle turrets to the main boss. The boss' health can't be whittled down until the two turret's are destroyed. Once the turrets are destroyed, the enemy starts to create three bullets. After the boss is at half health, the boss will create start another attack phase. (machine gun)

So my dilema: Each phase is controlled via a separate if statement. So it WORKs, but its not exactly fun. Rather than one attack at TIME, I'd rather have a cycle of attacks. Here's a good example on what i'm looking for.

https://www.youtube.com/watch?v=44yzlQTyHQM

Are coroutines better? I tried to create a boss cycle function, but i still don't understand coroutines well enough. (it didn't work) Thanks for any help you can provide.

Comment
Add comment · Show 2
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 whydoidoit · Dec 15, 2012 at 06:39 AM 0
Share

The coroutines++ video on Unity Gems might help you out with a bit more about using coroutines for multiple step operations.

avatar image MarvinH · Dec 15, 2012 at 04:53 PM 0
Share

Here's my code for clarification (current)

function Update(){

if (LevelController.Hardpoint<=0){

//hopefully this only instantiates once here's my code as it stands...

Heading if(LevelController.Turret <=0) { //Start the boss attacks with projectiles?

if (health>75) {

     if (Time.time > lastShot + FireFreq)
     { //set up a fire rate

         Attack1();

     }   

 }

 if (Time.time > lastShot + FireFreq2)
         { //set up a fire rate
             Attack2();
         }   
     }

 }

}

1 Reply

· Add your reply
  • Sort: 
avatar image
2

Answer by Jake.OConnor · Dec 15, 2012 at 06:06 AM

I don't have any links to tutorials or specific code for you (since I don't know what your code looks like), but I can help you out with a basic coroutine to control the boss AI. First of all, start this coroutine once you want the battle to start.

In the coroutine, use while loops with the boss health as the condition and inside do whatever you need to do (call shoot functions, etc) and then yield. Have as many while loops as the boss has attack cycles (you could even make this more abstract to allow you to set multiple boss types easier).

 while(m_rBossHealth > 80.0f)
 {
    vDoBasicAttack();
    yield return new WaitForSeconds(m_rBasicAtkTime);
 {
 
 while(m_rBossHealth > 50.0f)
 {
    vDoWoundedAttack();
    yield return new WaitForSeconds(m_rWoundedAtkTime);
 }
 
 while(m_rBossHealth > 20.0f)
 {
    vDoSevereAttack();
    yield return new WaitForSeconds(m_rSevereAtkTime);
 }
 
 while(m_rBossHealth > 0.0f)
 {
    vDoCriticalAttack();
    yield return new WaitForSeconds(m_rCriticalAtkTime);
 }
 
 Destroy(this.gameObject);

This sort of coroutine will automatically have your boss do his attacks at the speed that you set and will destroy him once he's dead. Just replace and rework to fit your specific code requirements.

Comment
Add comment · Show 1 · 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 MarvinH · Dec 15, 2012 at 04:52 PM 0
Share

Thanks Jake!

Here's my code, it actually is kind of conditional based. It would be nice if I could also run two attacks at once (ie call 2 functions) Also, how do I declare the code above? Is it Coroutine (insert code)? Thanks

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

11 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

Related Questions

Inconsistent script results/error 1 Answer

Enemy AI kills player once it gets really close? 1 Answer

How to make Enemy AI and Health 1 Answer

how to refer to enemy health 2 Answers

How to issue order to enemies 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