I think I'm getting it!

So, despite Rick telling me to stick to the ‘Projectile.cs’ I decided to use 2 scripts to solve the issues:

In the Health.cs - when something dies - I delete the collider - seemed easy enough to make sure arrows would pass over dead bodies.

As for the Projectile.cs - My solution allows you to turn homing on and off per projectile, as well as allow non-homing arrows to miss - as well as changing the ‘last shot fired’ from a homing missile into a non-homing missile if the target dies - so it will also just continue shooting straight. See my code - could probably be refactored or condensed - but hey it worked!

    [SerializeField] float speed = 1;
    [SerializeField] bool isHoming = false;

    Health target = null;
    float damage = 0;
    bool shotsFired = false;

    void Update()
    {
        if (target == null) return;

        if (isHoming)
        {
            transform.LookAt(GetAimLocation());
            shotsFired = true;
            if (target.IsDead())
            {
                isHoming = false;
            }
        }
        else if (!shotsFired)
        {
            transform.LookAt(GetAimLocation());
            shotsFired = true;
        }
        
        transform.Translate(Vector3.forward * speed * Time.deltaTime);
    }

Ha! Just finished lecture after doing challenge - yay! I did condense my code down to match Rick’s because … I used a lot of extra code to accomplish the exact same thing! Well - except for the whole removing the collider - hopefully that doesn’t cause me issues later on.

Well done!

Ultimately, it doesn’t matter during the challenges if you find the same solution as Rick or Sam, what’s important is thinking through the challenges. You thought through the problem and crafted a solution. This is, in fact, evidence that you are getting it. :slight_smile:

Privacy & Terms