Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 14 Next capture
2021 2022 2023
2 captures
13 Jun 22 - 14 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 SVGK · Jul 10, 2014 at 09:12 PM · groupscontain

How to force an object to stay inside a trigger collider?.

Title says all, I need to be able to force a game-object to stay within the boundaries of a set of colliders, it must be able to exit one trigger collider and enter another one if they are overlapping, but not to ever be outside the boundaries of a trigger.

How should I go about this?, an if statement checking if it's still inside the a trigger, and then pushing it back if it isn't, would that work?, it needs to be subtle enough that it won't jitter when it tries to escape the boundaries, and simply act as if there were a wall there.

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 Owen-Reynolds · Jul 11, 2014 at 01:21 AM 0
Share

One thing to note, triggers only fire when you touch them, and stop touching them. They do not tell you when part of you leaves them. They make good "intruder detectors" but bad prison alarms.

You can shrink the trigger to compensate, but you often can't make a "check when part of you leaves this area" using triggers, esp, for oddly shapes.

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by ricardo_arango · Jul 10, 2014 at 09:32 PM

You could surround the object with non-trigger Colliders when it enters the trigger object. If you have an overlapping trigger then you would not create a boundary collider for that section where the triggers intersect.

Another approach would be to have code that checks for when the object tries to exit the Trigger volunme (OnTriggerExit) and then force the object's position back to where it was in the previous FixedUpdate, back inside the trigger. In this case to allow the objects to pass to the next trigger you would have a check in the OnTriggerExit to see if the object has entered the other trigger (which should happen as they overlap, right?).

I would recommend the first method as it's simpler.

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

23 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

Related Questions

Optimising for large groups of enemies 3 Answers

How to detect that my object is completely inside a box? 1 Answer

How to "network.instantiate" an object only in a certain group of clients. 0 Answers

Unity 2018 is not adding bundle identifier in Xcode Build Settings 1 Answer

How to affect a group of objects. 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