But fix when you die?

Found a bug when you die if you have a homing arrow and it shoots and you die before you get hit the next time you respawn it will go to your location and hit you doing damage.

[I fixed it using]

        private void Update()
        {
            if (target)
            {
                if (isHoming && !target.IsDead())
                {
                    transform.LookAt(GetAimLocation());
                }
				if (target.IsDead())
				{
                    target = null;
                    Destroy(gameObject);
				}
            }
            transform.Translate(Vector3.forward * (speed * Time.deltaTime));
        }

alos thank you for the code

Hmmm… that’s actually a pretty quick and easy fix…
What’s happening is the arrow continues homing in on you even when you’re dead… before respawn, this isn’t really a big deal, but it gets a little more serious when you respawn.
Let’s make a minor change to Projectile’s Update() method:

		private void Update()
		{
			if (target)
			{
				if(target.IsAlive())
				{
					transform.LookAt(target.transform.position+new Vector3(0,1,0));
				}
				else
				{
					target = null;
				}
			}
			transform.Translate(Vector3.forward * (speed * Time.deltaTime));
		}

This should abort all homing once the target is dead.

2 Likes

Privacy & Terms