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 Deygus · Nov 29, 2015 at 12:57 AM · playerfallingdeath

Whats a good way to kill player if they go below a certain area?

I need some advice or some help pointing me in the right direction on how to create a script that would kill off the player if they fell off the course and falling down below a certain point.

So for instance my course is scaled 50 tall on the Y Axis and say I want to kill off the player if they reach below 25 or something like that.

Any advice on how to do that?

alt text

I'm still looking around trying to figure this out better though I'm still trying to get the hang of scripting.

2015-11-28-20h01-26.png (135.2 kB)
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
Best Answer

Answer by Natecurt · Nov 29, 2015 at 02:44 AM

Assuming that on the players death you would like to simply restart the game you can do:

function death() { Application.LoadLevel("SceneNameHere"); }

This is essentially the same as hitting the play button and will start the game from the scene's start. If not what are you looking to happen upon death?

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 Natecurt · Nov 29, 2015 at 03:09 AM 0
Share

Also, in c# you could try:

     public GameObject player;
 public Transform destination;

 void Update () {
     {
         if(player.transform.position.y < 25) {
             this.player.transform.position = destination.position;
         }
     }
 }

Then you would need to select a game object as the destination and set the FirstPersonCharacter as the player. Also, attach the script to the FirstPersonController. $$anonymous$$aker sure the box collider on the gameobject is disabled as well.

avatar image Deygus · Nov 29, 2015 at 04:11 PM 0
Share

Thanks for the help, you rock! I will go ahead and give that a try.

avatar image Deygus · Nov 30, 2015 at 11:37 PM 0
Share

@natecurt

Hmm...I think I messed something up in it...though I feel your answer is still the best because I feel strongly that it has gotten the closest to what I am trying to achieve. Ty.

I thought it was working at first but even after disabling the collider I am now noticing that the Player which is a ball that I have a camera controller attached to is getting sent to the destination point before falling to below 25 Y. So with that happening I can't even move the player anymore at all now because it's getting already sent to destination point for some odd reason.

I'm currently trying to figure out why this is happening...but I think I'm doing something wrong somewhere.

$$anonymous$$y friend said doing it that way would keep the script running and only create lag since it would continously run? Any idea if that that is true? I'm not sure.

So as an alternative I kept your suggested script for the time until I can figure out how to fix it. But, I've detached it and made a simple secondary script that is set to destroy the player object if it hits a non-rendered plane that I placed 25 Y. The script is attached to the plane.

 void OnTriggerEnter(Collider other) {
         Destroy(other.gameObject);
     }

However, I found some other threads saying it's better to disable the object and recall it ins$$anonymous$$d of destroying it. But, opposingly I also found some other threads spawning new objects that were previously destroyed.

$$anonymous$$y Start & Restart Point are positioned at 0x, 0y, 0z

I was looking at both to try to understand it more. So I am attempting to figure out how to fix this and reset the object either that way or another way with your provided script which seems to make more sense though I'm very confused at this point still.

avatar image
1

Answer by $$anonymous$$ · Dec 03, 2015 at 06:30 PM

First thing first.

1: Take off the camera controller script. 2: Take off the main camera from the player Object. ' Second thing to do (and the easiest)

1: create another camera and remove its audio listener. 2: Attach that second camera naming it Player Camera and make it a child of the player ball 3: Position the Player Camera in the angle or view you prefer,

Third thing; Barrier

Different people have different preferences for different styles of games so that is why you are getting confused. Don't worry about "how they want it." You need to figure out how things will work for you on the back-end of things.

If you use a barrier as "a point of no return" to kill the player if they fall into that abyss, then you can do something very simple, you just make a flat place, remove the visible aspect of the mesh, name it and tag it barrier, and slap on it something like the script from the Space Shooter game tutorial as;

using UnityEngine; using System.Collections;

public class Barrier : MonoBehaviour { void OnTriggerExit(Collider other) { Destroy(other.gameObject); } }

All I did here was change the file name as Barrier rather than "DestroyByBoundary." It does not really matter and in reality the only thing having it listed in player health or destruction or whatever is so that this specific file is found.

Instead of making a whole single box (which also can cause problems like sucking players outside of it or into it soon as you turn the game on), just create a cube, make it flat and transparent and set it however high or low you want it. If you want side barriers, just do the same thing by creating barrier walls.

As far as options, it is again up to you. You can set it up to kill someone if they hit those barriers, or simply restart them back at the starting location, or a combination of the two if you are doing a setup like "how many lives" one has to play before the game is completely over.

If you want the camera to still act as in a following type manner, use the secondary one and reserve the main camera for UI.

If you can pull off a really disturbing feature, when the player hits the barrier from the fall and you set up a scene to be replayed, or you just want to be funny and add something odd instead, you can also have it where if the player hits said barrier to play cut scene before restarting at designated start point.

Comment
Add comment · Show 5 · 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 Deygus · Dec 03, 2015 at 10:36 PM 0
Share

Thank you for the detailed example and help. I'll try doing it that way and see how it works out.

avatar image $$anonymous$$ Deygus · Dec 04, 2015 at 10:07 AM 0
Share

good luck I hope it does help.

avatar image Deygus $$anonymous$$ · Dec 04, 2015 at 01:14 PM 0
Share

Yeah, I'm sure i'll need the luck, thanks again. I owe ya one.

Show more comments
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

36 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

Related Questions

How to fix player from falling an inch when scene starts? 2 Answers

VRChat Player falls through floor regardless of colliders 0 Answers

Why is my player dying when defeating an enemy? 1 Answer

how to restart without time,.timescale effecting it 2 Answers

Unity Character Falls Slowly 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