public void TeleportHumanoid() { if (!active) { return; } HumanoidControl humanoid = transformToTeleport.GetComponent <HumanoidControl>(); if (humanoid == null) { transformToTeleport.Teleport(focusPointObj.transform.position); } else { Vector3 interactionPointerPosition = humanoid.GetHumanoidPosition() - transformToTeleport.position; switch (transportType) { case TransportType.Teleport: transformToTeleport.Teleport(focusPointObj.transform.position - interactionPointerPosition); break; case TransportType.Dash: StartCoroutine(TransformMovements.DashCoroutine(transformToTeleport, focusPointObj.transform.position - interactionPointerPosition)); break; default: break; } } }
/// <summary> Teleport the transform to a position and rotation </summary> /// This function will teleport the given transform to this teleport target using the /// teleport target settings. /// If the targetPosRot is set to TargetPosRot.Pointer, the transform will be transported /// using the transform of the gameObject as there is no pointer information. /// <param name="transform">The transform to teleport</param> /// <param name="position">The new world position of the transform after teleporting</param> /// <param name="rotation">The new world rotation of the transform after teleporting</param> /// <param name="movementType">The movement type to use to get to the target</param> /// <param name="newParent">The new parent of the transform after teleporting</param> protected virtual void Teleport(Transform transform, Vector3 position, Quaternion rotation, MovementType movementType = MovementType.Teleport, Transform newParent = null) { if (newParent != null && transform.parent == newParent) { // The transform is already at the teleport target, do not teleport again return; } Vector3 originPosition = transform.position; HumanoidControl humanoid = transform.GetComponent <HumanoidControl>(); if (humanoid != null) { Vector3 humanoidPosition = humanoid.GetHumanoidPosition(); Vector3 deltaHumanoid = humanoidPosition - transform.position; // We need to rotate the localHumanoidPosition so that it matches the new humanoid.transform rotation Quaternion rotateHumanoid = Quaternion.Inverse(transform.rotation) * rotation; deltaHumanoid = rotateHumanoid * deltaHumanoid; position -= deltaHumanoid; } if (teleportRoot) { Vector3 translation = position - originPosition; // World coordinates transform = transform.root; position = transform.position + translation; } transform.MoveTo(position, movementType); transform.rotation = rotation; transform.SetParent(newParent, true); }