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 candylandtiger · Jun 11, 2014 at 10:24 AM · collisionterrainrespawndeath

How do I make my character die when hitting the terrain?

Hello. I am new at Unity, and I am not exactly good at programming. I use JavaScript. I am creating a game where you have to jump on blocks and avoid the ground, aka the terrain. I am confused on how to die on contact with the terrain, have the game fade to black, and have my character respawn at the beginning of the level. Could somebody help me figure this out? Thanks! Also, this is a first-person 3D game.

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 Nick4 · Jun 11, 2014 at 10:47 AM

If you're new, you should look into some basic tutorials.

First off, you're going to need to attach a terrain collider to your terrain (which is unnecessary if you have just created one because it already comes with a terrain collider) and a regular collider to your character. Collider simply detects collision. This way when your character collides with the terrain you'll be able to collect collision data from a function called "OnCollisionEnter(collision : Collision)". Then inside this function, you're gonna need to check if it's your character that collided with the terrain with an if statement. Which will be something like this.

 function OnCollisionEnter(collision : Collision)
 {
     // In this case, your character must have the tag "Player"
     // just because we're checking whether collided object's tag is collider
     if(collision.transform.tag == "Player")
     {
         Respawn();
     }
 }
 
 function Respawn()
 {
     // Application.loadedLevel is the last loaded level which is the current one
     Application.LoadLevel(Application.loadedLevel);
 }

As you can see I've also added a Respawn function, which loads current level.

To fade the screen to black gradually requires a simple black guiTexture. Simply animate its alpha channel from 0 to 255 then play the animation right before respawning. Good luck.

Comment
Add comment · Show 3 · 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 candylandtiger · Jun 18, 2014 at 11:34 PM 0
Share

The script isn't exactly working. There is one error on the script. On line 5, it says unexpected char: ' '. (BCE0044) What can I do to fix this?

avatar image candylandtiger · Jun 18, 2014 at 11:54 PM 0
Share

Never $$anonymous$$d. I figured out the problem.

avatar image candylandtiger · Jun 19, 2014 at 01:43 AM 0
Share

I have another problem. The script isn't working. Could somebody help?

avatar image
0

Answer by Imposible · Jun 11, 2014 at 10:42 AM

Hi there!

i think the good idea for that is to check your player's collider....during OnTriggerEnter ... then check if your player collide with the Terrain.....then performs a die animation or whatever you want...

basic for this is use CharacterController.isGrounded to check if the player is on ground..

==neutra==

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

23 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

Related Questions

Can't crash airplane into ground 4 Answers

Camera Colliding with Terrain 1 Answer

Airplane - Collision With Terrain Problem 1 Answer

Stopping character from walking on grass 0 Answers

Death, Respawn and other things. 0 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