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 Siloaman · Jun 26, 2015 at 02:02 AM · collisioncollider

Use Collider like a radar...

Hey guys,

I am having major issues with the collider/collision concept it seems and I need a few clarifications.

The concept I am trying to make is like a submarine boat that uses sonar to detect other ships in the ocean. The boat itself has a collider (like a tube for its shape).

I added an empty GameObject, gave it a rigidbody component with zero mass and 'Is Kinematic' = true; and then added a sphere collider to the empty GameObject that can be adjusted to reach many hundreds of feet if necessary. I made this empty GameObject a child object of the boat.

Ideally, what I want to know is this:

  1. If two sonar detection signals (sphereColliders) bump into each other, to detect a collision and report what transform the boat is (by using the parent information of course)

  2. Do the OnCollisionEnter/Stay/Exit functions only work when the collision happens on the surface of the Collider? what happens if something is already inside the bounds of the collider? ( I ask this because I'm trying to report using Debug.Log(contact.otherCollider.name) and there is nothing to report even though my sample boats are all within range of each other).

I need some help with code that actually works because my usage of OnCollisionEnter and such is doing nothing at all in regards to collider detections.

 // Code //
 
 public SphereCollider sonarCollider;
 
 start(){sonarCollider.enabled = true;}
 
 void OnCollisionStay(Collision collision) {
 
         foreach (ContactPoint contact in collision.contacts) {
 
 Debug.Log(contact.thisCollider.name + " hit " + contact.otherCollider.name);
 
             print(contact.thisCollider.name + " hit " + contact.otherCollider.name);
 
             Debug.DrawRay(contact.point, contact.normal, Color.white);
         }
     }


..... and yet nothing is happening....

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 AlwaysSunny · Jun 26, 2015 at 02:02 AM

Be sure to always format your code with the 101010 button. I fixed it for you because it's a good question. ;)

Edit:

My original answer was quite thoroughly incorrect. Evidently I haven't been keeping up with the changelogs, because in the past, triggers did not respond to one another. Now apparently they do; I just tested and confirmed this. Lucky for you, because my old workaround technique was rather convoluted.

Anyhow, your "sonar" colliders should be triggers. These should have a kinematic rigidbody attached. When two overlap, they will both fire their OnTriggerEnter events.

By the way, is this a real phenomenon? Can one sonar device detect the activity of another if their fields overlap? Certainly your sonar trigger should respond when a non-trigger collider enters their trigger collider, but to other sonar triggers as well?

Comment
Add comment · Show 1 · 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 Siloaman · Jun 26, 2015 at 05:54 AM 0
Share

thanks for the clarification :) i'm not actually making a submarine/sonar game, but something similar ;) but your advice fits the bill perfectly!!

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

3 People are following this question.

avatar image avatar image avatar image

Related Questions

Problem about collisions between the cubes. 2 Answers

Collision with cloth not working,Cloth component not working 0 Answers

How to get the points of 2 collided objects 0 Answers

How do I “freeze” an object after a collision? 3 Answers

Camera Collision Not Working 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