Vector3 originalVector = new Vector3(1, 0, 0); float distanceToExtend = 2f; Vector3 extendedVector = originalVector.Extend(distanceToExtend); // The extendedVector will now have a magnitude of 3 (the originalVector's length was 1)
Vector3 objectPosition = transform.position; Vector3 targetPosition = new Vector3(10, 5, 0); float pushDistance = 2f; Vector3 pushDirection = (objectPosition - targetPosition).normalized; transform.position = objectPosition + pushDirection.Extend(pushDistance); // The object will now be pushed away from the target position by 2 unitsPackage library: The System Vector3 Extend function is part of the Unity engine's core libraries. Therefore, it is part of the UnityEngine namespace and does not require any additional packages or libraries.