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
0
Question by Uriel_96 · Aug 24, 2011 at 10:57 PM · collisioncolliderontriggerstaydetect

Detect 2 colliders by trigger

I am trying a system of covering and I have walls that have 4 colliders and 2 walls that 2 colliders get together and I want that if you get inside the 2 colliders the TriggerStay can identify that there are 2 colliders and to choose the new collider he just is trigger. I haven't see better the ContactPoint.otherCollider but it seems that's what I am looking for but it seems it only works for OnCollision not with OnTrigger so please someone help me to know a way to know if the player is in 2 colliders and if it is to choose the new collider he enter. I want something like this:

 function OnTriggerStay(other[] : Collider){//obviously all the code is wrong
 if(other[1]/*exists trigger with player*/){
 //player.direction = newcollider;
 }
 }
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
1
Best Answer

Answer by aldonaletto · Aug 25, 2011 at 01:05 AM

You can put the OnTrigger event in the Player script. If you enter a region where two triggers intersect, both triggers will call OnTriggerStay, so you will have two events at each cycle.
But I think it would be better to use OnTriggerEnter and OnTriggerExit:

var trig1: Collider;

function OnTriggerEnter(trig: Collider){ if (trig1){ // if player already in one trigger... // player goes to the new trigger trig.transform.position } else { // it's the first trigger trig1 = trig; // save its reference in trig1 } }

function OnTriggerExit(trig: Collider){ if (trig1==trig){ // if player left trigger 1 trig1 = null; // clear trig1 } }

Comment
Add comment · Show 2 · 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 Uriel_96 · Aug 25, 2011 at 01:22 AM 0
Share

ouhh, I get it, I haven't tested but seems good in logic. Thanks.

avatar image aldonaletto · Aug 25, 2011 at 01:27 AM 1
Share

trig1 "borns" with null value (but you can initialize it to null, if you want to be sure). When the player enters the first trigger (this script is assigned to the player) the script stores the trigger reference in trig1, thus when entering the second trigger the player will know it's already inside trigger 1 (trig1 is zeroed when the player leaves the first trigger). This works in any direction, since the first trigger entered sets trig1, no matter which one it is.

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

4 People are following this question.

avatar image avatar image avatar image avatar image

Related Questions

Checking and destroying a rigidbody? 2 Answers

OnTrigger* triggered only once 1 Answer

collider ignore other collider at a small angle 1 Answer

Collision flag entering a tagged object's collider 2 Answers

OnTrigger event when colliders are already touching eachother 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