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 Ishkur · Jul 24, 2013 at 05:35 AM · collisionraycastingfog of warline of sight

[Line of Sight] Please evaluate my approach

Hello, all. I'd really appreciate any critique to my approach before I go ahead and try to start implementing. I'm trying to make line of sight for an RTS environment. A unit should spot an other unit if two conditions are met:

  1. The two units are within detection range

  2. The two units have no obstacle between them

So two units within range but have a hill or building between them should not detect one another.


Every unit will have a large sphere collider to represent its maximum detection range. Upon collisionStay the collider will be added to an array of possible detected units and a raycast will be fired every frame toward the collider.

If the raycast hits, the target is deemed detected. Raycasts will continue to be fired to the target until it leaves the detection sphere and removed from the array of objects in detection range.


I'm afraid of performance issues due to the number of raycasts, however. If 10 units come into detection range of 10 enemy units, that would mean 100 raycasts are fired every frame. Is that an acceptable number of raycasts?

Comment
Add comment · Show 7
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 ikelaiah · Jul 24, 2013 at 05:46 AM 0
Share

What about attaching an invisible collider in the shape of your line of sight. Attach the inisible collider to a camera mount or something, then if it hits with anything at all, do whatever you need to do in function OnTriggerStay (otherObject : Collider) { // something here... }

avatar image chris_taylor · Jul 24, 2013 at 05:51 AM 0
Share

@$$anonymous$$elaiah I think thats is, from how I read it, basically what he is doing. Well except for the shape, he is using a sphere ins$$anonymous$$d.

avatar image ikelaiah · Jul 24, 2013 at 05:56 AM 0
Share

@chris_taylor Ah, I didn't read the question properly. Oh well, his approach seems sensible to me.

avatar image AlucardJay · Jul 24, 2013 at 05:56 AM 0
Share

Agreed, that's how I read the question too.

Alternative, why not just raycast every 0.1 to 0.2 seconds?

Lots of RTS question recently, so other people here are doing the $$anonymous$$iniLD44 7dRTS? :)

avatar image Ishkur · Jul 24, 2013 at 06:06 AM 0
Share

That many (or more) raycasts every 0.1-0.2 seconds wouldn't be too performance intensive?

What is this $$anonymous$$iniLD44 7dRTS? I've just been playing SupCom with my friends from the S$$anonymous$$m summer sale and got frustrated at its limitations, so I wanna make a better game to play with my friends.

Show more comments

1 Reply

· Add your reply
  • Sort: 
avatar image
1

Answer by chris_taylor · Jul 24, 2013 at 05:42 AM

I would use Rain{Indie} or at least look at how they do it, they also do raycasting. The best part is Rain{indie} is free and has a bunch of other features and the tornado twins use it in their FPS kit

http://rivaltheory.com/rainindie/

Comment
Add comment · 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

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

18 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

Related Questions

Block OnMouse~ whith UI 0 Answers

problem with raycasts and imported mesh 0 Answers

How to render a lot of the same small objects 2 Answers

Direction/Hit Detection without triggers. 1 Answer

2D Raycasting to detect if a player isGrounded 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