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 Matt 12 · Aug 30, 2010 at 01:42 PM · collisionphysicsoverlap

Detecting mesh collisions after the fact (overlap)?

Is it possible to detect when two colliders overlap but NOT due to a collision? I have a time travel mechanic that involves enabling/disabling large portions of the scene. From the player's perspective, he can travel forward/backward in time and the scene changes around him, but his position does not. This means he can easily end up inside a rock or a wall. I need to detect that overlap and correct it.

I can do this manually with a series of ray collisions on each axis to determine if the player is stuck inside a collider, or if a collider is stuck inside the player, but it's a little clumsy and possibly slow or prone to errors. Is there any way to leverage PhysX to do this for me?

Comment
Add comment · Show 3
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 skovacs1 · Aug 30, 2010 at 04:42 PM 0
Share

Have you tried using Collider.OnCollisionStay()? Since the objects you won't be colliding with will be disabled, and objects you aren't overlapping shouldn't fire the function, it should only get fired once, but bear in $$anonymous$$d that the physics engine is likely raycasting internally to deter$$anonymous$$e if it should fire the function.

avatar image skovacs1 · Aug 30, 2010 at 04:48 PM 0
Share

Doing it yourself, raycasting can have a layer mask which can speed it up a lot. A quick improvement is to simply check against a radiusSquared around your gameObjects to deter$$anonymous$$e if you should raycast against them (you could even put this in $$anonymous$$onoBehaviour.OnEnable) and then when you are done enabling stuff, only raycast against the objects close enough to your character from the side of their capsule which faces the object. If they don't hit, then you're inside (assumes convex colliders).

avatar image Matt 12 · Aug 30, 2010 at 10:21 PM 0
Share

I can check OnCollisionStay again but I seem to recall that it wouldn't fire if the colliders suddenly appeared overlapping and did not actually collide.

And also, convex colliders isn't an option. It's gotta work on complicated objects.

2 Replies

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

Answer by Matt 12 · Aug 30, 2010 at 11:29 PM

Haha, that was easy. Just made the player a rigid body with appropriate controller, now PhysX takes care of the problem for me. There's a few corner cases I need to check for but those should be easy.

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
avatar image
0

Answer by xinlog · Dec 05, 2010 at 04:00 AM

You can detect by raycasting from the camera :

RaycastHit hit; Ray ray = Camera.main.ScreenPointToRay(Camera.main.WorldToScreenPoint(detectedPos)); if(Physics.Raycast(ray,out hit)){ //overlap } else{ //not overlap }

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

No one has followed this question yet.

Related Questions

Enemy bouncing physics 0 Answers

How to avoid a gameobject inside another while they're in collision? 0 Answers

Normal vector from collision? 1 Answer

Bump when crossing box colliders 1 Answer

How can i create a character like dragon hill game, Digging underground, what collider should i use? 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