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 rejwan1 · Jul 04, 2012 at 10:25 PM · raycastairtscollisions

Aggro behavior for RTS game

Hello, I'm working on a RTS game using Unity - and I was wondering regarding how to implement the following:

In my game I plan to have up to around 60 friendly units and about 150 enemies. All enemies/friendly units that a unit from the opposite team comes in range, and has a clear line of sight with - automatically attacks the target, considering the following:

  1. All units can have varying ranges of sight.

  2. A unit can always target only 1 unit

  3. Once a unit has left the range of another unit, it can not attack it

Now I have come up with 2 solutions, and I was wondering which is the best way (or if there is a 3rd, better way) to do it:

  1. Put a sphere trigger collider on all units, and keep track of all units coming in and out of trigger events - every update I run through all the units inside my collider and fire ray casts to see that the unit has a clear LOS on the other unit.

  2. For every unit every update I go through all enemy units and check if they are in range. If a unit is in range, I fire a raycast and check if it's visible.

Thanks!

Comment
Add comment · Show 1
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 rejwan1 · Jul 04, 2012 at 10:37 PM 0
Share

BTW, forgot to mention that I put a delay on both methods so they don't really happen every update, but every 500ms.

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by Mortoc · Jul 05, 2012 at 10:29 PM

Two things I'd do to modify the approach there:

1) Use Physics.OverlapSphere (http://docs.unity3d.com/Documentation/ScriptReference/Physics.OverlapSphere.html) instead of sphere colliders to do your range checking.

2) Make sure the delay is offset somewhat. Making them only update every 500ms is great, but if they all trigger on the same moment you're still going to have a framerate drop. (Chances are you're already doing this, I just wanted to include it in case)

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 rejwan1 · Jul 05, 2012 at 11:04 PM 0
Share

Thanks for the advice, I'll try this approach tomorrow.

Right now I've tried the 2nd approach, all those colliders really lagged down my FPS.

avatar image rejwan1 · Jul 06, 2012 at 05:10 PM 0
Share

Well, I've tried using the OverlapSphere method - but right now the distance checking method seems to be the most efficient. Testing with 500 enemies and 100 friendlies, I got about 38FPS~ using the distance method and around 34FPS~ using OverlapSphere.

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

7 People are following this question.

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

Related Questions

Raycasting crashing Unity? 3 Answers

How to control order of executiing scripts? 1 Answer

WayPoints mixed with Raycast 1 Answer

Jitter on Slerp - Raycast 0 Answers

AI bug issue 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