Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 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 MaximilianPs · May 03, 2016 at 01:29 PM · raycastcollidersraycasting

RTS Object selection Ignoring Colliders

I'm working on a sort of RTS where you'll be able to select object (character) and click around to move it. To do this I'm casting a Ray from mouse if the hit object have the interactive class, I'll consider it selected.

Now the problem is 'cause I need to add second collider which is pretty whide 'cause is used for attack range.

alt text

Obviously the ray hit this collider ignoring all other units inside of his radius.... and I'm stuck :\

That's why I need to ignore the shperecollider but not the box collider.... advice?

cattura.jpg (36.3 kB)
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

2 Replies

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

Answer by FortisVenaliter · May 03, 2016 at 07:55 PM

Well, one way would be to utilize the physics layers, found in Edit->Project Settings->Physics. You can customize which objects collide with others, and specify a layer on your raycast.

The other option, which I'd highly recommend, would be to use a simple script that stores the attack radius as a float, rather than as a sphere bounding volume, and do that math manually, since the sphere isn't a real collider.

Comment
Add comment · Show 5 · 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 MaximilianPs · May 04, 2016 at 07:01 AM 0
Share

You mean to made a list with all enemies and attack the inside the range, ins$$anonymous$$d using a collider. not exalt me, but I guess it's the easiest way to achieve the same result.

Alt text

$$anonymous$$aybe I could create an Empty Object as Child, and place there Sphere Collider, than mede the child-object as IgnoreRaycast Alt text

avatar image MaximilianPs · May 04, 2016 at 05:02 PM 0
Share

Huston, can u help me with "do that math manually" ? :)

avatar image FortisVenaliter MaximilianPs · May 04, 2016 at 05:48 PM 1
Share

It would be something like:

 bool inRange = (my.transform.position-other.transform.position).magnitude < attackRadius;
avatar image MaximilianPs FortisVenaliter · May 04, 2016 at 07:20 PM 0
Share

so, in Update (or FixedUpdate) I should check with a foreach(unit in EnemyList) if the are in range?

isn't very CPU expensive ?

AT$$anonymous$$ i've achieved by adding a RigidBody (use gravity uncheck) to the object with the SpehereCollider which sit on layer Ignore Raycast. On this way, the sphere does not interfere with mouse raycast, and with a method which sit on the child object I pass the colliders to the parent.

Show more comments
avatar image
1

Answer by lactus · May 04, 2016 at 06:30 PM

don't use physics for selecting more than one unit.

Back in my old wild days I used Physics.OverlapSphere() to select units by dragging GUI.Box()es over them. It was incredibly slow. A better way is using a List of selectable Entities und check if their position in screenSpace (Camera.main.WorldToScreenPoint(obj.transform.position)) is in my selection-rect.

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 MaximilianPs · May 04, 2016 at 07:14 PM 0
Share

Yes, but $$anonymous$$e is an RTS and they should fight also when are off-screen.

avatar image lactus · May 07, 2016 at 11:52 AM 0
Share

just selecting, attacking will work diffrent.

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

55 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

Related Questions

Raycast not hitting the collider properly it always has a weird offset 0 Answers

Raycasting to make Buildings Clickable 1 Answer

How can I let the ray to the edge of the capsule? 1 Answer

Raycast origin overlapping surface of collider counts as a hit 0 Answers

Even-odd test with raycasting 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