/// <summary> /// Set the rotation on the object to a weighted average of the targets' rotations and apply offset /// </summary> public override void Compute() { // update normalized target weights ProcessTargetList(); // store the constraint targets as QuaternionBlendTargets StoreQuaternionTargets(); // determine the desired rotation based on the interpType _desiredRotation = QuaternionHelpers.Interpolate(_targetRotations, interpType, ref _cache, _oneOverTargetListLength); // set rotation constrainedObject.rotation = _desiredRotation * Quaternion.Euler(offset); }
/// <summary> /// Aim the aimVector on the object at the weighted average position of the targets and apply offset /// </summary> public override void Compute() { // update target list length ProcessTargetList(); // determine the desired up-vector based on the worldUpType switch (worldUpType) { case AimConstraint.WorldUpType.SceneUp: _desiredUpVector = Vector3.up; break; case AimConstraint.WorldUpType.ObjectUp: _desiredUpVector = worldUpObject.position - constrainedObject.position; break; case AimConstraint.WorldUpType.ObjectRotationUp: _desiredUpVector = worldUpObject.TransformDirection(worldUpVector); break; case AimConstraint.WorldUpType.Vector: _desiredUpVector = worldUpVector; break; case AimConstraint.WorldUpType.None: // TODO: This presently just does the same thing as SceneUp _desiredUpVector = Vector3.up; break; } // get target aim vector using weighted average of target vectors _desiredAimVector = Vector3.zero; _constrainedObjectPosition = constrainedObject.position; for (int i = 0; i < targets.Length; i++) { _desiredAimVector += targets[i].weight * (targets[i].position - _constrainedObjectPosition); } _desiredAimVector *= _oneOverTargetListLength; // set rotation constrainedObject.rotation = QuaternionHelpers.CustomLookRotation(_desiredAimVector, _desiredUpVector, aimVector, upVector) * Quaternion.Euler(offset); }