Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 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 DragonSaige · Aug 26, 2012 at 11:14 AM · collisiontriggerrespawn

How do I make a character die when he fells.

What I'm trying to do is whenever the player falls from the main ground and enters hellzone which is placed underneath main ground a function is called."hellzone" here is a simple plane with isTrigger and isKinematic on , it also has a tag applied to it saying "hell". On the other hand my player has a rigidbody with isKinematic off and a mesh collider with isTrigger off.

The problem here is that when I enter the "hellzone" nothing happens, my player keeps falling after it slips through "hellzone".

Here is the script that manipulates all this `

 // death from falling
 function OnTriggerEnter(other: Collider){
 
     if(other.gameObject.tag=="hell"){
         StartCoroutine(Respawn());
         Debug.Log("Collided");
     }
 
 }
 
 // Respawn
 function Respawn(){
 
     GameManager.lives--;
     renderer.gameObject.active = false;
     yield WaitForSeconds(respawnTime);
     transform.position = respawnPoint.position;
     renderer.gameObject.active = true;
     
 }







Also, here is the entire player script just in case you need to look through that

 var speed:float;
 var gravity_:float;
 var jumpSpeed:float;
 private var grounded = true;
 var respawnTime:float = 5.0;
 var respawnPoint:Transform;
 
 function Start () {
 
 }
 
 function FixedUpdate () {
 
 // movement
     var amtToMove:float = speed*Input.GetAxis("Horizontal")*Time.deltaTime;
     transform.Translate(amtToMove,0,0,Space.World);
 
 // Jump implementation
     if(Input.GetKeyDown("space")&&grounded){    
         rigidbody.velocity = Vector3(0,jumpSpeed*Time.deltaTime,0);
     }
 // gravity implementation
     
     rigidbody.AddForce(Vector3(0,-gravity_*rigidbody.mass*Time.deltaTime,0));
     grounded=false;
 }
 
 
 function OnCollisionStay(other:Collision){
 
 
 // ground check
     if(other.gameObject.tag=="ground"){
         grounded = true;
     }
     
 }    
 // death from falling
 function OnTriggerEnter(other: Collider){
 
     if(other.gameObject.tag=="hell"){
         StartCoroutine(Respawn());
         Debug.Log("Collided");
     }
 
 }
 
 // Respawn
 function Respawn(){
 
     GameManager.lives--;
     renderer.gameObject.active = false;
     yield WaitForSeconds(respawnTime);
     transform.position = respawnPoint.position;
     renderer.gameObject.active = true;
     
 }
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
0
Best Answer

Answer by whydoidoit · Aug 26, 2012 at 11:17 AM

It's possible you character is moving too quickly and passes through the collider. You could try making the collider much taller and offsetting it or you could ensure that the collision mode is Continuous Dynamic on your player which should make the collision easier to detect.

MeshColliders are a bit tricky sometimes (subject to back face culling for instance) but I would have thought that it would be ok in this circumstance. You are often better off approximating a collision area for you player using a combination of primitives.

Comment
Add comment · Show 6 · 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 DragonSaige · Aug 26, 2012 at 11:40 AM 0
Share

Setting the collision mode to Continuous Dynamic didn't help but switching to box collider and then increasing it's size sure did, however there seems to be a problem, my position doesn't change to respawn point's position.

EDIT:since the lives decrease I'll assume that the Coroutine is being called but the "renderer.gameObject.active = false" doesn't work, what should I do?

avatar image whydoidoit · Aug 26, 2012 at 11:43 AM 0
Share

Yes that will be because when you make the game object inactive the coroutine will not be called again.

Just do:

   renderer.enabled = false;

   ...


   renderer.enabled = true;
avatar image DragonSaige · Aug 26, 2012 at 11:57 AM 0
Share

Hmm.. now yield WaitForSeconds(respawnTime); transform.position = respawnPoint.position; works but I've a question ,why doesn't doing renderer.enabled = false; make my character invisible?

avatar image DragonSaige · Aug 26, 2012 at 12:02 PM 0
Share

Nevertheless, you solved my problem with the exception of being invisible so I'll accept your answer as correct. Thanks a lot sir.

avatar image whydoidoit · Aug 26, 2012 at 12:22 PM 0
Share

Was that not what you wanted by making the game object inactive? Sorry maybe I've lost what you were trying to do there.

renderer.enabled will make your character invisible until the respawntime has passed.

Show more comments

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

8 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Trigger respawn after collision? 3 Answers

Trigger Respawn 1 Answer

If trigger hit, spawn it 1 Answer

Can't add Rigidbody component because collision prevents it 2 Answers

how to make triger fireball not to pass through spesific objects 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