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 /
  • Help Room /
avatar image
0
Question by Cubemaster · Feb 24, 2016 at 02:19 AM · collidertrigger

How do I make a platform fall after a player has left it?

I'm trying to create a platform that will stay in place while the player is on it, but directly after they leave, it falls down. I'm using this code:

 public class platformFall : MonoBehaviour {
     public Rigidbody rb;
     void Start(){ 
         rb.isKinematic = true;
     }
     void OnTriggerExit(Collider other) {
         rb.isKinematic = false;
     Debug.Log ("Exit"); 
     }
     
     void OnTriggerEnter(Collider other){
 
         Debug.Log ("Enter");
     }
 
 }

on the platform. The player and the platform both have colliders, and I can see that they are set up properly (The collider for the platform is far above it). However, when the player moves about halfway across the platform, it falls early. They should definitely still be in the trigger area, but it still falls each time. Even stranger, the Debug.Log tells me that the player "enters" the trigger area many times, even though this should only happen once. Is there any way to fix this? I've tried a few other ways to do this but always encounter problems.

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

2 Replies

· Add your reply
  • Sort: 
avatar image
0

Answer by Jason2014 · Feb 24, 2016 at 09:19 AM

Add Rigidbody to the platform with "Use Gravity" property switched off and replace "OnTriggerExit" to "OnCollisionExit". Triggers works when player can "enter" in a specified radius of collider set as trigger. In "OnCollisionExit" function just switch "Use Gravity" to on.

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 Statement · Feb 24, 2016 at 09:34 AM

However, when the player moves about halfway across the platform, it falls early.

It sounds like you should make your trigger bigger.

They should definitely still be in the trigger area, but it still falls each time.

Given your trigger is large enough, it is mysterious. Maybe you have multiple colliders on your player that get turned off, or leave the area?

Even stranger, the Debug.Log tells me that the player "enters" the trigger area many times, even though this should only happen once.

If you have multiple colliders on your player, this is not strange.

Here's something you can try: Checking if the object in the trigger belongs to the player (so it doesn't register the object you'd stand on) and ref counting, in case the player is made of multiple colliders.

 // NOTE: Requires collider game objects tagged Player
 public class platformFall : MonoBehaviour
 {
     public Rigidbody rb;
     int colliders;
 
     void Start() {
         rb.isKinematic = true;
     }
 
     void OnTriggerEnter(Collider other) {
         if (IsPlayer(other) && colliders++ == 0)
             PlayerEntered();
     }
 
     void OnTriggerExit(Collider other) {
         if (IsPlayer(other) && --colliders == 0)
             PlayerExited();
     }
 
     bool IsPlayer(Collider other) {
         return other.tag == "Player";
     }
 
     void PlayerEntered() {
         print("Enter");
     }
 
     void PlayerExited() {
         print("Exit");
         rb.isKinematic = false;
     }
 }
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

57 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

Related Questions

Trigger FinishLine 1 Answer

How i make one trigger work if there only one object in it ? 0 Answers

How to detect collision of two moving characters? 1 Answer

How to handle enemy dying inside trigger collider? 2 Answers

Problem with 2D Triggers 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