x


Death on Lava collision

Translation: I'm not a really good programmer and I'm trying to make my character 'die' when he falls on lava. How would I go forth doing this?

Original Message:

i am making a game where if the character touches the lava he dies...now i am horrible...HORRIBLE with scripting for right now so i really need help with how to do this...PLEASE HELP!!!

more ▼

asked Apr 13 '11 at 12:36 PM

david 4 gravatar image

david 4
8 6 8 9

Batman, I think you're just too old for it, buddy.

Apr 13 '11 at 12:50 PM Jessy

[Flame Post]

Apr 13 '11 at 01:11 PM david 4

Geez, when I read that title I thought someone was gonna get killed!!!!!!!!!!!!!!!!!!!!!!

Apr 13 '11 at 01:13 PM Proclyon

smh......^^^^^^

Apr 13 '11 at 01:15 PM david 4

What I'm saying is, I remember when you were really good at using your batputer. It's time to move on to cursing the kids on the Wayne Manor lawn, old-timer.

Apr 13 '11 at 01:43 PM Jessy
(comments are locked)
10|3000 characters needed characters left

2 answers: sort voted first

// A grenade // - instantiates a explosion prefab when hitting a surface // - then destroys itself

 var explosionPrefab : Transform;

  function OnCollisionEnter(collision : Collision) {
 // Rotate the object so that the y-axis faces along the normal of the surface
    var contact : ContactPoint = collision.contacts[0];
    var rot : Quaternion = Quaternion.FromToRotation(Vector3.up, contact.normal);
    var pos : Vector3 = contact.point;
    Instantiate(explosionPrefab, pos, rot);
    // Destroy the projectile
    Destroy (gameObject);
      }

http://unity3d.com/support/documentation/ScriptReference/Collider.OnCollisionEnter.html

http://unity3d.com/support/documentation/ScriptReference/Object.Destroy.html

more ▼

answered Apr 13 '11 at 12:42 PM

robertmathew gravatar image

robertmathew
571 35 41 51

(comments are locked)
10|3000 characters needed characters left

If you have the code in place for your character dieing, you only got to call that function.

So basically you would create something like:

private void CheckDeath(int Hp)     
 {

 if (hp = 0)    
 { 
    -execute wathever code you have for dieing, could be a message, together with a red overlay on the screen. And code to revive-    
 }
 }

And then for the touching itself, you would need a collider, but I haven't worked with those yet. (The basics should be in the link Robert posted.)

more ▼

answered May 24 '11 at 03:27 PM

Simon V gravatar image

Simon V
138 16 22 28

(comments are locked)
10|3000 characters needed characters left
Your answer
toggle preview:

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

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Topics:

x394
x64
x31
x14

asked: Apr 13 '11 at 12:36 PM

Seen: 1278 times

Last Updated: May 24 '11 at 03:29 PM