nudge to level

This commit is contained in:
Leijurv 2018-08-10 10:45:13 -07:00
parent 22a6a4285f
commit 9dd5aa21b1
No known key found for this signature in database
GPG Key ID: 44A3EA646EADAC6A

View File

@ -28,7 +28,7 @@ public class LookBehavior extends Behavior {
/** /**
* Target's values are as follows: * Target's values are as follows:
* * <p>
* getFirst() -> yaw * getFirst() -> yaw
* getSecond() -> pitch * getSecond() -> pitch
*/ */
@ -42,8 +42,21 @@ public class LookBehavior extends Behavior {
public void onPlayerUpdate() { public void onPlayerUpdate() {
if (target != null) { if (target != null) {
player().rotationYaw = target.getFirst(); player().rotationYaw = target.getFirst();
player().rotationPitch = target.getSecond(); float oldPitch = player().rotationPitch;
float desiredPitch = target.getSecond();
player().rotationPitch = desiredPitch;
if (desiredPitch == oldPitch) {
nudgeToLevel();
}
target = null; target = null;
} }
} }
private void nudgeToLevel() {
if (player().rotationPitch < -20) {
player().rotationPitch++;
} else if (player().rotationPitch > 10) {
player().rotationPitch--;
}
}
} }