- Home /
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 :)
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 [i] != null) { zombies [i].GetComponent ().detected = true; } } //Base Hit plus lifetime damage hit. myHealth = myHealth - (0.7f - other.GetComponent().lifeTimeDamage);
Answer by lefinno · Jun 01, 2017 at 01:46 PM
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
Answer by Tu-Le · May 30, 2017 at 07:05 AM
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