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 Mattivc · Mar 18, 2010 at 01:31 PM · physicscollider

If statment to check if player is within collider

I am creating a door that opens when the player enters the Collider box.

But how can i check to see if the player has left the collider box. So the door dosent close while the player is standing in the doorway, but automaticly closes when the player has moved away from the door.

I also need to make shure that if the player re-enters the collision box, while the door-close animation is playing. Then the door finishes the close animation but then immidetly plays the open animation.

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
3
Best Answer

Answer by duck · Mar 18, 2010 at 03:41 PM

Sounds like you're using the OnTriggerEnter function fine.

Now you just need to use the OnTriggerExit function to detect when the player leaves the collider.

If you really want to check whether the player is still currently within the collider, you could make use of the OnTriggerStay function, however from your description it sounds like the OnTriggerExit version is better suited.

In terms of the door completing its closing animation before re-opening, the implementation of that would be depending on what code you have already, however the general idea would probably involve having OnTriggerEnter and OnTriggerExit functions set a boolean flag, which allows the code to see whether the player is currently within the trigger area or not. Eg:

var playerInArea : boolean = false;

function OnTriggerEnter() { playerInArea = true; }

function OnTriggerExit() { playerInArea = false; }

You'd then just check whether the door should open based on both:

(playerInArea) and (door is completely closed)

hope this helps!

Comment
Add comment · Show 1 · 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 Vaupell · Jan 19, 2014 at 02:18 PM 0
Share

This is flawed.

If the player enters trigger, and exits before the animation is complete. The Bool will stay true, even with the player is out.

Need to check if the player "stayed" within trigger, this will also catch any "system hickups" where you could see someone enter a trigger but not triggering.

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

1 Person is following this question.

avatar image

Related Questions

The name 'Joystick' does not denote a valid type ('not found') 2 Answers

Collect some coins for Points 1 Answer

Physics.Raycast not checking layermask properly? 1 Answer

Continuously moving rigidbody 2 Answers

Colliders Not Doing Their Job 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