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
1
Question by mr16thprestige · May 12, 2012 at 10:42 PM · beginnerscriptingbasicsdeath

Death on impact with water

So i have a open ocean, on top of it are platforms. in my game you jump from platform to platform! object is to get to the finish line without touching the water! i'd like to make it so that when you touch the water u'r player die, and you respawn at the begining! so far there are no life counter, so loosing a life is not a relevant factor! i'm pretty ned to unity so effects like: fading to red upon death, ETC are not important! i'm using the default "first person controller" that comes with the program! i'm very new to unity so i'd appreciate if any responses where kept simple! posting a script won't be enough, i'm afraid! i need to know what to do with it! i'd be very glad for any help!

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
3
Best Answer

Answer by save · May 12, 2012 at 11:00 PM

You could have a collider set as trigger that upon collision initiates a sequence on the player.

 //Trigger collider script
 function OnTriggerEnter (other : Collider) {
     if (!other.CompareTag("Player") return; //Exit if this isn't the player
     var pScript : PlayerScript = other.GetComponent(PlayerScript); //Get the script component of the player (this could be cached for performance too)
     pScript.Kill(); //Run the function called Kill on the player
 }

 //Part of the player script
 private var startPos : Vector3;
 function Start () {
     startPos = transform.position;
 }
 
 function Kill () {
     animation.Play("death"); //Initiate the 'death' animation
     yield WaitForSeconds (animation["death"].length); //Wait for animation to finish
     transform.position = startPos; //Reposition the player at starting point
 }

If you don't use the physics engine you might as well want to check for a certain height, and when below that you initiate the kill function.

 private var startPos : Vector3;
 private var waterLevel : float = .0;
 private var isDead : boolean = false;

 function Start () {
     startPos = transform.position;
 }
 
 function Update () {
     if (transform.position.y < waterLevel && !isDead) Kill();
 }
 
 function Kill () {
     isDead = true;
     animation.Play("death");
     yield WaitForSeconds (animation["death"].length);
     transform.position = startPos;
     isDead = false;
 }
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 mr16thprestige · May 13, 2012 at 12:25 AM 0
Share

tnx for the scripts, but as i said i'm new, and i dunno exactly how to integrate it in my game! of course i assume i just click "create a new script" and paste this code. but then what! whats the simplest way of markign an object so that the player dies when co$$anonymous$$g in contact with it! i used the default "daylight water" for the visuals, and a water prefab i downloaded of the internet. (the prefab only creates the small waves in the water, the water does not react when my player comes in contact with it)

avatar image syclamoth · May 13, 2012 at 12:30 AM 1
Share

You need to add a collider to whatever you are using as water! I recommend making a big, invisible box trigger for this- when you create a collider there is a checkbox called 'Is Trigger'- set this to true.

As for the water 'reacting' when a player enters it- this stuff is tantamount to fluid simulation. The default water asset looks good from a distance, but definitely doesn't do that kind of complicated effect without serious modification.

In any case, if you want to make any kind of game mechanics at all, you'll need to do a little coding practice first. One of the few things Unity lacks is a magical 'make game' button- the fact is, games are about 90% program$$anonymous$$g, and there's not much you can do to change that.

avatar image save · May 13, 2012 at 12:39 AM 0
Share

@mr16thprestige As syclamoth says you need to have some fundamental knowledge of scripting before you're trying to make a game. I recommend you to start here.

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

5 People are following this question.

avatar image avatar image avatar image avatar image avatar image

Related Questions

Making a turret shoot at a low fire rate. 2 Answers

AI Awareness 2 Answers

Hide Objects on Higher Plane 0 Answers

Death script problem 2 Answers

Which is better, lots of if-statements or seperate button scripts? 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