float rotation = ArithmeticUtils.wrapAngleAroundZero(targetOrientation - owner.getOrientation());
@Override public AnimationDesc startAnimation(DogCharacter dog) { AnimationDesc animationDesc = super.startAnimation(dog); if (dog.currentTaskAnimation == getTaskAnimation()) { // Calculate target orientation to make the dog face human targetOrientation = ArithmeticUtils.wrapAngleAroundZero(dog.human.getOrientation() + Constants.PI); } return animationDesc; }
@Override public Status execute () { if (facingHuman) { return Status.SUCCEEDED; } DogCharacter dog = getObject(); updateAnimation(dog); if (dog.currentTaskAnimation == getTaskAnimation()) { // Get current model orientation float currentDogOrientation = dog.getBoneOrientation(DogCharacter.DogArmature.FRONT_SPINE.id); // Calculate the difference between current and target orientation float orientationDiff = ArithmeticUtils.wrapAngleAroundZero(currentDogOrientation - targetOrientation); // Is dog facing human with enough precision? if (MathUtils.isZero(orientationDiff, ORIENTATION_TOLERANCE)) { // Make the task succeed on the next frame facingHuman = true; // Bark GameScreen.screen.sounds.bark.play(); // Finish the animation truncateAnimationCleanly(dog, currentDogOrientation); } } return Status.RUNNING; }
float rotation = ArithmeticUtils.wrapAngleAroundZero(targetOrientation - owner.getOrientation());