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
1
Question by BuoyantOtter · Jun 25, 2018 at 07:39 AM · collisionphysicscollidercolliderscollision detection

Detect if a non-trigger collider is inside another collider

In a game I'm working on, the player can teleport into any point of the map. This results in a case where player can be teleported for example inside a rock (or any other solid object). When that happens, I want to disable all colliders of that rock object and enable them once player exits the object. I want all solid objects to have this functionality and for them to detect the player and not other way around.


Problem I am having is detecting when player is suddenly teleported inside another solid object, since they both have a solid colliders and not triggers. I'm just trying to figure out possible ways to achieve this and would appreciate some pointers in right direction.

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 Jjules · Jun 25, 2018 at 10:24 AM

I'm not sure allowing solid objects to move inside of each other, THEN fixing it on reaction is the best idea.

One approach would be to, right before teleporting, take the point you're teleporting to, and have the rock run a bounds.Contains on that point, and if it returns true, disable the object. The problem, though, is that this would have to run on every potential object every time the player teleported

Another solution would be to make the player's collider a trigger on the frame he teleports, setting isTrigger to true. Then, check for a collision on that frame, and if there is a collision, trigger some function in the other object to turn ITS collider into a trigger. Then the player can go back to a non-trigger on that frame, and the other object can use OnTriggerExit to know when the player is no longer inside of it

I know this isn't exactly the solution you were hoping for, but hopefully it gave you some idea of what direction to go in!

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 BuoyantOtter · Jun 25, 2018 at 12:02 PM 0
Share

Player can basically blindly pick a point in the map and teleport there. Which means that sometimes they might end up in a solid object and I can't prevent that. I can't set the collider to trigger either because where ever player is teleported the collider still needs to be able to collide with some objects (for example stand on ground, without falling through).

avatar image Jjules BuoyantOtter · Jun 27, 2018 at 02:28 AM 0
Share

You may not be able to prevent objects from going through each other, that's fine, I'm specifically saying having a "solid" object, as in a non trigger collider, inside of another isn't a good idea.

And if you do as I suggested, the player turns to a trigger literally for one frame, so there should be no collision issues because the player will be solid again before the user gets to move. It should also be too brief for the player to fall through the floor, but if they do you can always set the rigidbody to be kinematic on that frame and that problem shouldn't happen

avatar image ahstein BuoyantOtter · Jun 27, 2018 at 02:52 AM 0
Share

Can you add a second collider to the player, and set that one as a trigger and use itin the way Jjules described to detect the collisions?

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

187 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 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 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 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

Strange issue with collider 1 Answer

How to get OnTriggerEnter effect without using isTriggered on Collider? 1 Answer

OnCollisionEnter isnt called when player lands on object 1 Answer

Inconsistent Collision Detection 3 Answers

How to detect collision between 2 objects while checking are they the ones that need to collide? 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