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 /
avatar image
0
Question by nick 1 · Nov 30, 2010 at 09:43 PM · aifighting

enemy reacting to player

I'm trying to make an enemy know when to dodge and/or block an attack from the player, and I'm not sure how to start, I suppose using ray/line cast to see if the player is in sight but beyond that not too sure. If someone could point me in the right direction on how to do that, that would be great. I'm working in javascript but pseudo code is great

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 The_r0nin · Nov 30, 2010 at 10:06 PM 0
Share

A little more info might help. Do you mean a physical or a projectile attack? Do you want the enemy to stay in the same area or do you want them flee, zig-zag, etc.? There are a lot of conditions that you may have clear in your $$anonymous$$d that anyone trying to help you doesn't know. Also, what part of this process is causing you trouble? Detecting player attacks? Triggering an enemy response? Coding the movement algorithm?

Try breaking down your intended action into separate steps: Step one, is the player firing at me? Step two, deter$$anonymous$$e the direction of the attack. Then ask for help...

avatar image nick 1 · Dec 01, 2010 at 12:34 AM 0
Share

sorry about that, I would like the enemy to dodge projectile fire, and take cover. Coding the movement I know how to do, but detecting player attacks I'm unsure about. hope that clears up my question, I have a problem of having something in my head and not transferring it to other mediums.

1 Reply

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

Answer by The_r0nin · Dec 01, 2010 at 02:41 AM

You could check the distance from the player to all enemies (use FindGameObjectsWithTag and then a "for - in" to iterate through the enemies) on each gunshot and have the enemies react to the "sound." Or, you might want to :

if (gunshot){
   var enemiesList: GameObject[] = GameObject.FindGameObjectsWithTag("Enemy");
   for (var enemy: GameObject in enemiesList){
       if (enemy.renderer.isVisible){  // you might have to do a GetComponent to find the renderer, depending on your hierarchy
          // program your evasion routine here, or send a message to that enemy to evade.
       }
   }
}

This will make only the enemies in your camera (if you have only one camera... it will return "true" for every gameobject visible in ANY camera) react to the gunshots. This will simulate the enemies you are shooting at knowing that bullets are flying nearby... but the rest of the enemies will behave as normal (so you won't have enemies behind you running for cover).

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 nick 1 · Dec 01, 2010 at 05:02 AM 0
Share

Thanks The_r0nin this is exactly what I am looking for

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

No one has followed this question yet.

Related Questions

How to make 2 groups of agents attack eachother? 0 Answers

Making a fighter respond to being attacked 1 Answer

Rotate with Raycast??? 2 Answers

Following AI - Similar to Snake Game 2 Answers

Unity AI FPS problem 0 Answers


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