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 Michael 12 · Mar 12, 2012 at 04:45 PM · kill player

Make Player Drown in Mud Pit

I figured I would Update this instead of creating a new question. I managed to get something to work almost the way I want. The only issue I'm having with it it's lets say your player jumps towards a rock that in in the middle of the Mud Bog, and just misses and hits the bog but manages to hit the jump button. So what happens is, is that the code executes at a point where he is in mid air. It does not happen often but it sure looks funny when it does. I'm wondering if I can tweak something or add something to prevent that from happening. Here is what I've cobbled together so far, it looks really cool and basically works if he just ends up in the soup and does not manage to get that 2nd jump in.

 if ( IsGrounded && other.tag == "bogDeath" )                                                    // trigger for Mud Bog Death
     
     {
         
         canJumpAll = false;
         audio.PlayClipAtPoint ( playerDrowningSound, transform.position );        // Plays Audio Clip for Player Drowning (Needs to be assigned)
         Instantiate ( waterSplashParticle, transform.position, Quaternion.identity );// Instantiates a muddy water splash particle effect
         yield WaitForSeconds (0.5);                                                // Allows a slight time delay to allow player to sink into the Mud Bog
         isControllable = false;                                                    // Disables all player movements
         animation.Play ( aniMudDrown.name );                                    // Plays Drowning Animation
         yield WaitForSeconds (7.5);                                                // Allows a delay time for animation to play for a spell
         isControllable = true;                                                    // Re Enables all player movements
         Instantiate ( bogDeathParticle, transform.position, Quaternion.identity );// instantiates death Particle
         audio.PlayClipAtPoint ( dieSound, transform.position );                    // Play a dying audio clip (blood Splat)
         yield WaitForSeconds (0.1);                                                // waits 0.1 second before isKilled is called
         isKilled = true;                                                        // Sets isKilled to True
         life -= 1;                                                                // Reduces Players life by 1
         canJumpAll = true;
         Message ( "Player was drowned in a Mud Bog" );                            // Prints message "Player was drowned in a Mud Bog"    
     }
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

Answer by Kleptomaniac · Mar 14, 2012 at 12:18 PM

I believe that this should work, but tell me if it doesn't (don't often use OnCollisionEnter/OnCollisionStay/OnCollisionExit):

 private var mudDrown : AnimationClip;
 private var drownTime : float;
 private var timeSpeed : float;
 private var deathTime : float;
 
 function OnCollisionStay (hit : Collider) {
     if (hit.collider.gameObject.tag == "mud") {
         mudDrown.Play();
         drownTime += Time.deltaTime * timeSpeed;
         if (drownTime >= deathTime) {
             Destroy(gameObject);
         }
     }
 }
 
 function OnCollisionExit (hit : Collider) {
     if (hit.collider.gameObject.tag == "mud") {
         mudDrown.Stop();
         drownTime = 0;
     }
 }

Attach this to your player, assign your animation, specify your timeSpeed (rate of time incrementing) and deathTime (time elapsed before player dies), and set the mud object tag to "mud" and you're good to go.

Hope that helps, Klep

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 Michael 12 · Mar 14, 2012 at 05:55 PM 0
Share

I tried what you have here only modified slightly to fit into the Walker Boys Script... still did not seem to work. I updated my question with the code I'm using for that part, I'm not sure if yur familiar with the Walker Boys Script?? Calls the animations differently rather than directly.

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

Killing the player in a trigger zone. 1 Answer

Killer + assistance id for shooter game 1 Answer

What's wrong with my code? (Collision, JS) 2 Answers

Kill script on collision when lives are lost 1 Answer

how do you make a 3D game object destroy your player? 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