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 up2004523 · Mar 12, 2021 at 12:07 PM · unity 4

Target Priority

Hello everyone. I'm currently working on a dungeon crawler game and I have a level part that is going to be a wave of enemies prioritizing the attack of an object istead of the player. I wanted to create something like a random number, that way thy would attack the object more than the player. Anyone can help me to how I can create a target priority system? Thank you.

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
0

Answer by highpockets · Mar 12, 2021 at 12:50 PM

I think you can maybe come up with a functionality that creates a min distance for the enemy to attack the player, but as the enemies spawn, make that distance a random float:

 public class Enemy : MonoBehaviour
 {
     private float randomDist;
    
     private Transform player;
     
     private void Start()
     {
         randomDist = Random.Range(4.0f, 20.0f);
         player = GameObject.FindWithTag(“Player”);
     }
     private void Update()
     {
         if(Vector3.Distance(transform.position, player.position) <= randomDist)
         {
             //Attack player
         }
         else
             //Look for other opponents to attack
     }
 }
Comment
Add comment · Show 2 · 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 up2004523 · Mar 12, 2021 at 01:39 PM 0
Share

I thought about that the thing is, the player rich an area and only then the spawn point of the wave set active, if the player is too close to those point the enemy will prioritize the player instead of the object. What I want is more like tower defence, the enemies attack that object but there's a small probability of them attacking the player

avatar image highpockets up2004523 · Mar 12, 2021 at 03:37 PM 0
Share

Ok, well then you would have to create some functionality where if third party enemy is alive and within target range attack player by doing another random range. That random range can be 0-100 and if the returned number is 0-10 and you set the player attack probability to10 percent, then attack the player. It’s a similar thing really, but I don’t think you need to make it more complicated than that.

 float totalAttackFactor = 100;
 float attackPlayerProbability = 0.1f; //10 percent
 
 if(Random.Range(0,totalAttackFactor) <= attackPlayerProbability * totalAttackFactor)
 {
     //Attack player
 }
 else
 {
     //Attack third party 
 }
 

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

113 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 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 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 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 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 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 avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Draw Calls increased after I upgraded to 4.0 1 Answer

Unity 4 drag and drop no longer works? 1 Answer

Three ingame buttons conflict with each other on iOS 0 Answers

Why does my trigger-collider receive Enter but not Stay or Exit? 1 Answer

Edit font texture (unity 4) for adding special effects. 2 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