I can see how you wanted to prepare the lesson's challenge

(Just in case: Unique Video Reference: 11_BH_UPC )

Nonetheless, I consider it overly complicated to have a second Coroutine just for moving the shadow…

Unless there is more to come to do in the Coroutine I would simply define the shadow’s instance as a class variable, and add its movement to the ProjectileCurveRoutine.
As for the shadow being place below, that could just be configured in its prefab, or one could simply have some correction for it…

    GameObject grapeShadow;
    Vector3 shadowAdjust = new Vector3( 0, -0.3f, 0);

    void Start()
    {
        grapeShadow = Instantiate(/* ... */);
        StartCoroutine(ProjectileCurveRoutine(transform.position, playerPos));
    }

    private IEnumerator ProjectileCurveRoutine(Vector3 startPosition, Vector3 endPosition)
    {
        /* ... */
            transform.position = Vector2.Lerp(startPosition, endPosition, linearT) + new Vector2(0f, height);
            grapeShadow.transform.position = shadowAdjust + Vector2.Lerp(startPosition, endPosition, linearT);
        /* ... */
        Destroy(gameObject);
        Destroy(grapeShadow);
    }
1 Like

Happy I found your post as I was thinking the same thing during this lesson. I followed step by step but for some reason my shadow wasn’t moving with the instantiation.

So I attempted your approach and ran into one issue when trying to add ‘shadowAdjust’ to Vector2.Lerp in the grapeShadow.transform.position. Error was not being able to concatenate a Vector3 with a Vector2 variable.

However, I was able to make some minor adjustments to work around this. See screenshot for my final code:

1 Like

If you copy/pasted your code snippet as text it would be easier to read… :wink:

There must be some other difference in your project because I know it worked in mine.
Since you got it to work for your project eventually, that’s nothing to worry about, though. :slight_smile:

Privacy & Terms