void SmoothRotation() { float y = transform.eulerAngles.y; float deltaY = Angle.AngleDiff(requestedRotation.eulerAngles.y, transform.eulerAngles.y); float absDeltaY = Mathf.Abs(deltaY); const float minimumFramesToReachRotation = 2.0f; float maxSpeed = absDeltaY / Time.deltaTime / minimumFramesToReachRotation; float rampedSpeed = 5.0f + absDeltaY * absDeltaY; float speed = Mathf.Sign(deltaY) * Mathf.Clamp(rampedSpeed, 0, maxSpeed); // Debug.Log("SmoothRotation delta:" + deltaY + " target:" + requestedRotation.eulerAngles.y + " source:" + transform.eulerAngles.y + " speed:" + speed * Time.deltaTime); y += speed * Time.deltaTime; transform.eulerAngles = new Vector3(0, y, 0); }
private bool CloseEnoughToPerformAction() { Vector3 targetPosition = new Vector3(targetInteractPosition.x, 0, targetInteractPosition.z); Vector3 avatarPosition = new Vector3(characterWalking.transform.position.x, 0, characterWalking.transform.position.z); float distanceToInteractionPoint = (targetPosition - avatarPosition).magnitude; float deltaY = Mathf.Abs(Angle.AngleDiff(targetInteractRotation.eulerAngles.y, characterWalking.transform.eulerAngles.y)); // Debug.Log("RotationDiff:" + deltaY + " target:" + targetInteractRotation.eulerAngles.y + " source:" + characterWalking.transform.eulerAngles.y); if (deltaY > walkToPoint.MinRotation) { return(false); } Debug.Log("distanceToInteractionPoint " + distanceToInteractionPoint + " interactionDistanceThreshold " + interactionDistanceThreshold); return(distanceToInteractionPoint < interactionDistanceThreshold); }
bool IsRotatedToTarget(Quaternion desiredRotation) { var rotationDiff = Mathf.Abs(Angle.AngleDiff(desiredRotation.eulerAngles.y, vehicle.transform.rotation.eulerAngles.y)); return(rotationDiff < minRotation); }