Struggling with an error- Value cannot be null, parameter name source

Any help on this topic will be appreciated, as I have been struggling with this error for a little bit and don’t know where to start.

The error im getting shows that there is a null value. This error pops up when my enemy pirate ship is attempting to shoot at the player.

When double clicking on the error, it takes me to the following code snippet:

private void TurnTowardsPlayer()
Vector3 direction = playerTransform.position - transform.position;

            // Calculate the rotation angle in degrees
            float angle = Mathf.Atan2(direction.y, direction.x) * Mathf.Rad2Deg;

            // Create a quaternion rotation using the calculated angle
            Quaternion rotation = Quaternion.AngleAxis(angle, Vector3.forward);

            // Apply the rotation to the object's transform
            transform.rotation = Quaternion.Lerp(transform.rotation, rotation, 0.5f);

hopefully this is enough information to get started, any help is appreciated!

also, for some odd reason it appears to try to tell me that the transform of the object this script is attached to is the null value, as that is what is highlighted when double clicking on the error

Privacy & Terms