Revisión | d4381efdd2f061ad49774af2a557996f01d34dbf (tree) |
---|---|
Tiempo | 2021-05-06 18:26:08 |
Autor | sebastian_bugiu |
Commiter | sebastian_bugiu |
Fixed AI limits reached turn around.
@@ -100,6 +100,7 @@ | ||
100 | 100 | // Set the AI to turn around its ship. |
101 | 101 | InvisibleWallRigidBody invisibleWallRigidBody = (InvisibleWallRigidBody) nextColObj; |
102 | 102 | invisibleWallRigidBody.getInvisibleWall().getWallType().getLimitReached(entityProperties.getLimitsReachedOriginal()); |
103 | + System.out.println("Level limit: " + entityProperties.getLimitsReached() + " reached"); | |
103 | 104 | } |
104 | 105 | |
105 | 106 | return entityDestroyed; |
@@ -106,9 +106,12 @@ | ||
106 | 106 | private final ENG_Vector4D patrolingRotationAxis = new ENG_Vector4D(); |
107 | 107 | private final ENG_ClosestObjectData data = new ENG_ClosestObjectData(); |
108 | 108 | private final ENG_Vector4D levelLimits = new ENG_Vector4D(); |
109 | + private final ENG_Vector4D currentLevelLimits = new ENG_Vector4D(); | |
109 | 110 | private final ENG_Vector4D awayFromLimitsPos = new ENG_Vector4D(); |
110 | 111 | private final ENG_Vector4D destination = new ENG_Vector4D(true); |
111 | 112 | private final float updateInterval; |
113 | + private boolean rotationAwayFromLimitsCompleted = true; | |
114 | + private boolean awayFromLimitsPosSet; | |
112 | 115 | // private float beginTime; |
113 | 116 | |
114 | 117 | public AISystem(double interval) { |
@@ -884,7 +887,9 @@ | ||
884 | 887 | |
885 | 888 | private void evadeLevelLimits(AIProperties aiProperties, EntityProperties entityProperties, ShipProperties shipProperties) { |
886 | 889 | entityProperties.getLimitsReached(levelLimits); |
887 | - if (levelLimits.equals(ENG_Math.VEC4_ZERO)) { | |
890 | + // Even if we are no longer touching the level limits we must still complete | |
891 | + // the turn around. | |
892 | + if (levelLimits.equals(ENG_Math.VEC4_ZERO) && rotationAwayFromLimitsCompleted) { | |
888 | 893 | aiProperties.setState(AIState.SEEK_CLOSEST_PLAYER); |
889 | 894 | showAIStateChange(shipProperties, aiProperties); |
890 | 895 | } else { |
@@ -892,25 +897,40 @@ | ||
892 | 897 | // will end up with previous limits never going away since they are |
893 | 898 | // only additive in EntityContactListener. |
894 | 899 | entityProperties.resetLimitsReached(); |
895 | - levelLimits.invert(awayFromLimitsPos); | |
896 | - float angleBetween = currentFrontVec.angleBetween(awayFromLimitsPos); | |
900 | + // If we have new level limits should we check and recreate awayFromLimitsPos? | |
901 | + if (awayFromLimitsPosSet && !levelLimits.equals(currentLevelLimits)) { | |
902 | + System.out.println("levelLimits: " + levelLimits + " currentLevelLimits: " + currentLevelLimits); | |
903 | + } | |
904 | + if (!awayFromLimitsPosSet) { | |
905 | + levelLimits.invert(awayFromLimitsPos); | |
906 | + currentLevelLimits.set(levelLimits); | |
907 | + // First slow down to 0 then rotate away. | |
908 | + entityProperties.setVelocity(0.0f); | |
909 | + awayFromLimitsPosSet = true; | |
910 | + rotationAwayFromLimitsCompleted = false; | |
911 | + } | |
912 | + | |
897 | 913 | // awayFromLimitsPos.addInPlace(entityProperties.getNode().getPosition()); |
898 | 914 | entityProperties.getNode().getPosition(currentPos); |
899 | 915 | entityProperties.getNode().getLocalInverseZAxis(currentFrontVec); |
900 | 916 | // entityProperties.getNode().getLocalYAxis(currentUpVec); |
901 | 917 | |
902 | - // First slow down to 0 then rotate away. | |
903 | - entityProperties.setVelocity(0.0f); | |
918 | + float angleBetween = currentFrontVec.angleBetween(awayFromLimitsPos); | |
919 | + | |
920 | + | |
904 | 921 | // ENG_Math.rotateTowardPositionDeg(awayFromLimitsPos, currentPos, currentFrontVec, currentUpVec, rotation, getRotationAngle(shipProperties)); |
905 | 922 | // entityProperties.rotate(rotation, true, TransformSpace.TS_WORLD); |
906 | - Utility.rotateToPosition(currentFrontVec, | |
907 | - awayFromLimitsPos, | |
908 | - updateInterval, entityProperties, | |
909 | - shipProperties.getShipData().maxAngularVelocity); | |
923 | + rotateTowardPosition(entityProperties, shipProperties, awayFromLimitsPos); | |
924 | +// Utility.rotateToPosition(currentFrontVec, | |
925 | +// awayFromLimitsPos, | |
926 | +// updateInterval, entityProperties, | |
927 | +// shipProperties.getShipData().maxAngularVelocity); | |
910 | 928 | |
911 | 929 | |
912 | 930 | |
913 | 931 | if (angleBetween < ESCAPE_LEVEL_LIMITS_ANGLE) { |
932 | + rotationAwayFromLimitsCompleted = true; | |
933 | + awayFromLimitsPosSet = false; | |
914 | 934 | // Also get to max speed |
915 | 935 | changeVelocity(entityProperties, shipProperties, aiProperties, new VelocityChange( |
916 | 936 | VELOCITY_CHANGE_NAME_ESCAPING_LIMITS, |