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 Luke 4 · Apr 28, 2011 at 04:26 PM · collisionraycastspherelayermaskcheck

Collision between sambe objects with same Layer

Hi,

i am kind of confused as i am trying to make one type of enemy prevent coliding with other enemies of the same type ( its the same enemy instantiated more times). I wanted to use checksphere, but here i get into the problem. If i just use the checksphere it collides with itself. But when i assign layer, which the checksphere should check, it also check itself. And when i invet the layer, then of course it wont find the enemy as all enemies are inverted.

I am realy confused how to check collisions between enemies of the same type. Please note i need them to check close position, not collision. I.e. i need them to evade each other, not collide, thats why i do the check. I tried raycasting, but its too heavy and i would need raycasting in more directions and it just isnt working too good in comparsion as how expensive it is.

Thanks for any advise.

Luke

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 Joshua · Apr 28, 2011 at 05:16 PM 0
Share

Can't you use Vector3.Distance to see how close they are and make them move away from eachother when they are too close?

avatar image Luke 4 · Apr 28, 2011 at 05:25 PM 0
Share

thanks for reply. I was thinking about this solution, but i am sure it would be very expensive as there can be up to 10 instances of same object in scene, so you would be comparing one object distance to 9 other objects each frame, then doing another calculations for translating position. This happing for each of these object.

Also i dont know how i would find all those objects, because they all have same names and tags, so how the object would know wich one is which to move in opposite direction.

Iam sure there must be way with something similar to checkSphere, but i dont know about it :(

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by Bunny83 · Apr 28, 2011 at 05:20 PM

Make sure you have setup the collision matrix as you need it.

You can use Physics.IgnoreCollision to setup an individual behaviour, but layer based collsion is more appropriate in your case.


To get all nearby colliders use Physics.OverlapSphere. It will return an array of all colliders that are "in range". You can also specify a layermask.


edit

I think i still don't get your problem.
Do you :

  1. want no collisions by the Unity physics-system because you want to use your own collision-avoidance-system?
  2. need help creating your own flocking style AI?
  3. just need some help to understand how layerbased collisions or raycasts/OverlapSphere works?

In case of 1. i recommend to ignore collisions for the layer in your collision matrix. That way the physics system will not detect collisions between objects of that layer. Now you have to take care of when two enemies come close and what they should do to avoid collisions.
If you don't know how collision avoidance works, well, you have to inform yourself. There are a lot of different ways to implement such a behaviour. Collision avoidance is continuous process. Like i mentioned above with OverlapSphere you can get a list of all nearby enemies that are within a certain range. I can't tell you how your collision response should look like because it depends on how your enemies are moved. If they can turn instantly or not, if they can move sideways/backwards or not.

You just said you have problems but your explanations are not very clear. Maybe you can update your question and post some of your code. I'm trying to read between the lines but i can't spot your actual problem.

Comment
Add comment · Show 3 · 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 Luke 4 · Apr 28, 2011 at 09:45 PM 0
Share

thanks for reply, but i think this wouldnt help as it utilize layer masks again or i guess i dont understand it well. How does this help with the problem of the same instantiated objects checking for each other. As i said, i am not looking for collision, but more for something like checksphere where objects checks if other is in close range.

avatar image Bunny83 · Apr 29, 2011 at 01:45 AM 0
Share

I've updated my answer.

avatar image Luke 4 · Apr 29, 2011 at 07:49 AM 0
Share

I am sorrry if i wasnt clear. I am looking for something like flocking AI (i.e. enemies are aware of each other, they are moving, but they dont collide with each other). I will try to look up more on the flocking AI, but if you can direct me to some good resource, i would be very thankful. ( Also i dont want them to have any collisisons, also another thing is all the enemies have same tags, same layers as they are one instantiated type, thats why i cant use something like checksphere )

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

Obstacle Avoidance 0 Answers

BoxCollider2D is not working as expected 1 Answer

How does Raycast layer mask work? 1 Answer

How do I find the normal of the closest surface (in a specific radius)? 3 Answers

Align to grid in runtime problem 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