fall damage issue?

 0 when my player falls in a certain hight then i want to apply some damage but i don't know how to calculate hight & then how to apply damage e.g. if the player falls some height then apply some damage to the player like that for the damage i using FPS damage script just decrease the GUI width thnaks i make two game object one is my character mesh & attach box collider & Health script to this game object & for the movement i make one more gameobject & i attach movement script to this game object (movement script is my own script) thats what i don't where attach below script & hw to work this script ``````var speed =50.0; var raydist = 1.0; var rayoffset = 1.0; static var maxspeed = 5.0; var airxspeedfactor = 2; var jumpforce = 1000; static var grounded = 1; var damage = 10.0; function FixedUpdate () { transform.position.z = 0; //print (rigidbody.velocity.x); if (Physics.Raycast ((transform.position+ Vector3 (rayoffset, rayoffset, rayoffset)), Vector3 (0, -1, 0), raydist)) { //print ("Grounded"); grounded = 1; transform.rigidbody.AddForce((Input.GetAxis("Horizontal") * speed), 0, 0); rigidbody.velocity.x = Mathf.Clamp(rigidbody.velocity.x, -maxspeed, maxspeed); //rigidbody.drag=1.75; // if (Input.GetButtonDown("Vertical")) // { // transform.rigidbody.AddForce(0, jumpforce, 0); } else { //print ("Clear"); grounded = 0; transform.rigidbody.AddForce((Input.GetAxis("Horizontal") * speed / airxspeedfactor), 0, 0); rigidbody.velocity.x = Mathf.Clamp(rigidbody.velocity.x, -maxspeed, maxspeed); //rigidbody.drag = 0; } } function OnCollisionEnter(collision : Collision) { // Only give damage if speed is greater than 10 var relSpeed : float = collision.relativeVelocity.magnitude; if (relSpeed > 10.0) { print ("ok1"); //The amount of damage increases linearly with speed from //v = 10 (giving zero damage) to v = 50 (giving 1 damage) SendMessage ("ApplyDamage", damage, SendMessageOptions.DontRequireReceiver ); } } `````` more ▼ asked Mar 26 '10 at 08:41 PM Apexuni 72 ● 14 ● 15 ● 22 Ostagar 166 ● 1 ● 3 ● 9 add new comment (comments are locked) 10|3000 characters needed characters left ▼ Viewable by all users

 0 EDIT: As it says 'enhanced' character controller, replace your standard controller with this script. Make a new javascript file. Then, copy the enhanced walker code into it. Save it. Then, select your first person controller. Remove the standard walker script. Next, drag your new script onto it, thereby replacing the old walker script with the new one you just downloaded. That should do the trick. However, you're not finished yet. Find this script: ``````function FallingDamageAlert (fallDistance : float) { Debug.Log ("Ouch! Fell " + fallDistance + " units!"); //Put your falling script here, and if you want, get rid of the Debug.Log line. } `````` It's near the bottom. That's where you can put what happens if you fall, such as subtracting health, shaking, blurring, or otherwise discoloring the GUI, etc. Good luck! Oh, and don't forget to fix the settings, like checking the falling damage option and such. You really should just use the standerd FPS prefab for this, as it makes things a lot simpler. You shouldn't need much else, unless you want to replace the 'Graphics' component with your own personal mesh. All it is an object that can be affected by physics, so it's not a big deal if you replace it. For clarity, though, keep the name to 'Graphics' no matter what mesh you have, in case a unknown script references it from somewhere and can't find it. Although that's very unlikely, it's also nice to keep your game streamlined and as simple as possible. I believe this is what you're looking for. Check it out! more ▼ answered Mar 26 '10 at 10:49 PM e.bonneville 5.7k ● 100 ● 116 ● 165 hey i try this script but nothing happen..... i add more information please see my question again Thanks Mar 27 '10 at 07:17 AM Apexuni as you say in your script that subtracting health that's what i add this send massage here like gameObject.SendMessage ("ApplyDamage", damage, SendMessageOptions.DontRequireReceiver ); but its not working Mar 29 '10 at 05:45 AM Apexuni hey i slove this problem. can i call this fuction only one time means. one fall one damage & then if player fall again then second damage. Apr 02 '10 at 06:05 PM Apexuni add new comment (comments are locked) 10|3000 characters needed characters left ▼ Viewable by all users
 0 The easiest thing would probably be if you instead of using the height the player has fallen, used the velocity of the player when he collides with the ground. You can get the relative velocity of a collision in the `OnCollisionEnter` method ``````function OnCollisionEnter(collision : Collision) { // Only give damage if speed is greater than 10 var relSpeed : float = collision.relativeVelocity.magnitude; if (relSpeed > 10.0) { //The amount of damage increases linearly with speed from //v = 10 (giving zero damage) to v = 50 (giving 1 damage) var damage : float = Mathf.Clamp((relSpeed - 10.0)/50.0, 0.0, 1.0); //give the damage somehow } } `````` more ▼ answered Mar 26 '10 at 10:00 PM KvanteTore 1.5k ● 8 ● 15 ● 33 hey i try this script but nothing happen..... i add more information please see my question again Thanks Mar 27 '10 at 07:17 AM Apexuni You need to actually do something with the `damage`, like subtract it from your health. Mar 27 '10 at 08:02 AM KvanteTore However, I would think that the EnhancedFPSWalker elbon95 linked to is more appropriate for your needs. Mar 27 '10 at 08:03 AM KvanteTore i upload my whole movement script can you tell me whats wrong in this script check my question. Mar 27 '10 at 09:11 AM Apexuni but the problem is when i changed relspeed for e.g. 20 then this script is not working Mar 28 '10 at 08:49 PM Apexuni add new comment (comments are locked) 10|3000 characters needed characters left ▼ Viewable by all users

By Email:

Topics:

x5064
x248
x97

asked: Mar 26 '10 at 08:41 PM

Seen: 1727 times

Last Updated: Nov 05 '10 at 05:48 PM