Bullet timer using + time.deltaTime.

Hey

Im making a prototype Payer vs Zombies game and im having a big headache.

im making a top down AI where the player start shotting the zombie when it get to a sertain distance, but i want to make the damage to be more and more when the player get closer ,so far i have this script on the bullet, but does not seems to be working , anyone here that knows a simple solution? i would realy love that :slight_smile:

here is the script i have so far.

public float lifeTimeDamage;

// Use this for initialization
void Start () {

 Destroy (gameObject, 3f);

}

// Update is called once per frame
void Update () {

 lifeTimeDamage += Time.deltaTime * 6f;

 
 transform.position -= transform.forward * Time.deltaTime * bulletSpeed;

and the Zombie

and this on the zombie script

void OnTriggerEnter(Collider other)
{ if (other.tag == “Bullet”) { for(int i = 0; i < zombies.Length; i++) {
if (zombies != null) { zombies .GetComponent ().detected = true; } }
//Base Hit plus lifetime damage hit.
myHealth = myHealth - (0.7f - other.GetComponent().lifeTimeDamage);

you can try calculating the distance between the player and the zombie and subtract the distance and the damage, sth like this:

var distance = Vector3.Distance(object1.transform.position, object2.transform.position);

damage = damage - distance*multiplyByYourOwnNeeds

it’s really simply, and you idea seem to be right, maybe the way you check collider are wrong.
my way:
-player shoot bullet
//stronger when closer meaning the damage of bullet decrease over time
-buttleDamage -= time.DeltaTime* rate

  • when Bullet hit a Zombile, run hit Function and Destroy Bullet