|
Post by Yort_Draeb on Oct 20, 2019 20:27:49 GMT
Thanks for this script, saved me a good amount of time Let me post a slightly optimized version with less component calls. using UnityEngine; using System.Collections; using Invector.CharacterController;
public class vFallDamageManager : MonoBehaviour { public float damageThreshold = 3f; public float damageMultiplier = 2.85f;
vThirdPersonController vController;
float startYPos, endYPos; bool firstCall = true; bool damaged = false;
void Awake () { vController = GetComponent<vThirdPersonController> (); }
void Update () { if (!vController.isGrounded) { if (transform.position.y > startYPos) { firstCall = true; } if (firstCall) { firstCall = false; damaged = true; startYPos = transform.position.y; } } else { endYPos = transform.position.y; if (damaged && (startYPos - endYPos) > damageThreshold) { damaged = false; firstCall = true;
float amount = startYPos - endYPos - damageThreshold; float damage = (damageMultiplier == 0f) ? amount : amount * damageMultiplier; vController.currentHealth -= Mathf.Round (damage); } } } }
I get an error after updating the invector namespace Health is handled differently now than it was when this was created. You just have to update your code to handle that change
|
|
|
Post by conairgames on Nov 12, 2019 14:06:52 GMT
Hey this script worked great except for one thing. If you climb down a ladder that is over 3 meters tall when you hit the ground you lose health or die. To stop that if anyone has trouble with it just add this: if (!vController.isGrounded && vController.verticalVelocity < -9); -9 is the value i found that works for me you may need more or less for your game.
|
|