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 antx · Feb 19, 2013 at 06:55 PM · gameobjectrigidbodycheckcollsion

Is there a way to explicitly check for collision?

I have gameObjects in my scene that need to be aware of whether they are colliding at startup (for inititalisation) with other gameObjects or not. Since they can´t have a rigidbody all the time I wanted to add a rigidbody to each gameObject in Start(), check whether they collide with something, store that information and remove the rigidbody again.

Now I wonder if there is a way to force a collision check for a gameObject at a specific place in code.

Anyone have a clue if that is possible?

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 AlucardJay · Feb 20, 2013 at 01:24 AM 2
Share
  • http://docs.unity3d.com/Documentation/ScriptReference/Collider.OnCollisionStay.html

  • http://docs.unity3d.com/Documentation/ScriptReference/Collider.OnTriggerStay.html

1 Reply

· Add your reply
  • Sort: 
avatar image
1

Answer by nullstar · Feb 20, 2013 at 09:43 AM

Unfortunately this isn't possible since Unity's wrapper around PhysX is retardedly restrictive. Using Unity functionality you could approximate a collision check using raycasts or spherecasts. If you need accurate collision though you've no option but to implement your own collision detection routines.

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 antx · Feb 20, 2013 at 10:52 AM 0
Share

Hmmmm, okay. I was afraid this would be the answer. It´s pretty annoying and leads to really crazy workarounds.

Then how can I be certain that all objects have handled all their collisions? Lets say there are 1000 gameobjects intersecting with each other. How can I know that they all have handled their OnCollisionEnter() for all of those intersections? Is there a timeframe I can rely on?

It´s pretty silly that the code is actually there in the Unity system, but developers can just not access it due to a lack of an API for it. :-(

avatar image nullstar · Feb 20, 2013 at 11:12 AM 0
Share

Unity physics runs in sync with $$anonymous$$onobehaviour.FixedUpdate. If you add all your objects during one FixedUpdate call then the next time that FixedUpdate is called all the initial contacts should have been processed.

avatar image save · Feb 20, 2013 at 11:16 AM 0
Share

You could use something like this on each object:

 static var collisionCount : int;
 private var collided : boolean = false;
 
 function OnCollisionEnter () {
     Collide();
 }
 
 function OnCollisionStay () {
     Collide();
 }
 
 function Collide () {
     if (collided) return;
     collisionCount++;
     if (collisionCount>=1000)
         Debug.Log(collisionCount+" collisions has occured!");
     collided = true;
 }

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

12 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

Related Questions

Check if object is applying force to another object 0 Answers

Creating a teleportation gun 1 Answer

Horizontal gravity on One gameobject 2 Answers

Creating a retractable grappling hook 1 Answer

Get force applied on a gameobject 2 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