- Home /
 
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"    
     }
 
              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
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