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 TheCrimsonMoon · Jun 14, 2019 at 09:22 PM · unity 5scripting problemphysicsontriggerenterrespawn

unity sometime execute instruction and sometime ignore same instruction ?!

Greetings

I have script which respawn player if he fall into water ( water object is plane ), this water object send damage to player health then player die and respawn to spawn point. But sometime player does not respawn and he is keep falling then i need to restart the game.

these are the scripts

Player health:

     public int maxHealth = 100;
 
     public Transform spawnPoint;
 
     public int health = 100;
 
     private bool isDead;
 
     void Start()
     {
         health = maxHealth;
     }
 
     void Update()
     {
         if(isDead)
         {
             Respawn();
         }
         
     }
 
     public void TakeDamage(int amount)
     {
         health -= amount;
 
         if (health <= 0)
             Die();
     }
 
     void Die()
     {
         isDead = true;
     }
 
     void Respawn()
     {
         transform.position = spawnPoint.position;
         health = maxHealth;
         isDead = false;
     }


Water:

 public int damage = 100;
 
     private void OnTriggerEnter(Collider other)
     {
         if (other.gameObject.CompareTag("Player"))
         {
             other.GetComponent<PlayerHealth>().TakeDamage(damage);
         }
     }


what is the problem ?!

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
1

Answer by talyh · Jun 15, 2019 at 04:29 AM

Planes are paper thin, so it seems the collision is not being detected on some cases. That’s a common issue. You’ll likely want to make your water have a collision box with some height to allow a couple of frames of contact between player and water to ensure the collision is identified.

Also, as a fallback, you may have some checks on the player’s vertical position. If it’s less than whatever makes sense, the player fell out of the world and should be killed.

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 TheCrimsonMoon · Jun 18, 2019 at 12:56 AM 0
Share

Thank you for your replay

i have detected where is the problem.

the problem in Update function when i 've changed it to FixedUpdate function, it detect the collisions (Trigger) better than Update function. and to make sure water detect player, i've changed mesh collider to Box collider. Plus, if player falls into water repeatedly, he may can pass the collider (Trigger) and keep fall down again and go back to same problem.

avatar image
1

Answer by Bunny83 · Jun 14, 2019 at 09:32 PM

What kind of collider does your water "plane" object use? You should use a box collider with sufficient thickness. If the player moves at a high velocity it's possible that the player misses a plane mesh collider and just falls "through". At the right speed there will be no overlap between the colliders.


Have you actually checked with a Debug.Log if you enter the OnTriggerEnter method when your player falls through the trigger? If it doesn't fire, there will be no overlap. Of course all this assumes that you player actually has a rigidbody attached.

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 TheCrimsonMoon · Jun 18, 2019 at 12:56 AM 0
Share

Thank you for your replay

i have detected where is the problem.

the problem in Update function when i 've changed it to FixedUpdate function, it detect the collisions (Trigger) better than Update function. and to make sure water detect player, i've changed mesh collider to Box collider. Plus, if player falls into water repeatedly, he may can pass the collider (Trigger) and keep fall down again and go back to same problem.

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

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

RigidBody.velocity or transform.position 1 Answer

HELP! Scripts looks fine but doesn't respond? 1 Answer

How do I use UNetWeaver.dll during runtime? 0 Answers

How to count from 2nd collision 1 Answer

When my player dies and i hit revive button i want my player back to the game but i m unable to do that please help. 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