Calculating point on a ray/vector

The shooting functionality I have is currently spawning my projectile in the center of the player objects transform position. I want to offset that spawn position such that it actually spawns on the outside of my player objects mesh, which is currently a sphere with a radius of .5 units. This calculation must be relative to the direction that I’m firing the projectile, which is calculated by subtracting the position of the player object from the position of the target, which in the case of the player is the cursor position (converted to world coordinates) and in the case of the enemy is the position of the player.

In the past, I used a fixed “weapon” object as a spawn point. This object was rotating on a turret with a fixed length slightly longer than that of the radius of the sphere, so no calculations were necessary as the projectile would just spawn there.

After refactoring, I have gotten rid of this turret and weapon object, leaving only the player object but I need to manually calculate the new spawn position.

Here is a screencap to give you a visualization of what I need:

How do I calculate this? I’m sure there must be some simple formula or something. Here is the code if it helps:

        public void Rotate(Transform target)
        {
            if (target)
            {
                _aimPosition = target.position;
                _aimDirectionV3 = _aimPosition - _gameObject.transform.position;
                _aimRotation = Quaternion.FromToRotation(Vector3.up, _aimDirectionV3);
            }
            else
            {
                _aimPosition = _camera.ScreenToWorldPoint(Mouse.current.position.ReadValue());
                _aimDirectionV3 = _aimPosition - _gameObject.transform.position;
                _aimDirectionV2 = _aimDirectionV3; // Hack for zeroing out z-axis without creating
                _aimDirectionV3 = _aimDirectionV2; // new Vector3 in the middle of update loop !NO LONGER IN UPDATE LOOP!
                _aimRotation = Quaternion.FromToRotation(Vector3.up, _aimDirectionV3);
            }
        }

Okay I think I found a solution. Basically, I’m using Vector3.ClampMagnitude on my initial _aimDirection value to return another vector with a fixed length no greater than the length of how far out I want it to spawn. I then add this vector to the current position of my objects transform, and store that value in a new variable called _spawnPosition.

This seems to work in most cases, however, it will be problematic in situations where the user has his target/cursor at a distance less than that of the radius of the player object, in which no clamping on the vector will occur. Clamping isn’t exactly what I need, however it works in most cases. I need more of an absolute solution that works in every case.

Easier than I thought. I just change my spawn point to the aim direction normalized value, and multiply that value * a length factor