• R/O
  • SSH

Commit

Tags
Keine Tags

Frequently used words (click to add to your profile)

javac++androidlinuxc#windowsobjective-ccocoa誰得qtpythonphprubygameguibathyscaphec計画中(planning stage)翻訳omegatframeworktwitterdomtestvb.netdirectxゲームエンジンbtronarduinopreviewer

Commit MetaInfo

Revisiond4381efdd2f061ad49774af2a557996f01d34dbf (tree)
Zeit2021-05-06 18:26:08
Autorsebastian_bugiu
Commitersebastian_bugiu

Log Message

Fixed AI limits reached turn around.

Ändern Zusammenfassung

Diff

diff -r 2493ad6671f9 -r d4381efdd2f0 core/src/headwayent/blackholedarksun/physics/EntityContactListener.java
--- a/core/src/headwayent/blackholedarksun/physics/EntityContactListener.java Wed May 05 23:33:43 2021 +0300
+++ b/core/src/headwayent/blackholedarksun/physics/EntityContactListener.java Thu May 06 12:26:08 2021 +0300
@@ -100,6 +100,7 @@
100100 // Set the AI to turn around its ship.
101101 InvisibleWallRigidBody invisibleWallRigidBody = (InvisibleWallRigidBody) nextColObj;
102102 invisibleWallRigidBody.getInvisibleWall().getWallType().getLimitReached(entityProperties.getLimitsReachedOriginal());
103+ System.out.println("Level limit: " + entityProperties.getLimitsReached() + " reached");
103104 }
104105
105106 return entityDestroyed;
diff -r 2493ad6671f9 -r d4381efdd2f0 core/src/headwayent/blackholedarksun/systems/AISystem.java
--- a/core/src/headwayent/blackholedarksun/systems/AISystem.java Wed May 05 23:33:43 2021 +0300
+++ b/core/src/headwayent/blackholedarksun/systems/AISystem.java Thu May 06 12:26:08 2021 +0300
@@ -106,9 +106,12 @@
106106 private final ENG_Vector4D patrolingRotationAxis = new ENG_Vector4D();
107107 private final ENG_ClosestObjectData data = new ENG_ClosestObjectData();
108108 private final ENG_Vector4D levelLimits = new ENG_Vector4D();
109+ private final ENG_Vector4D currentLevelLimits = new ENG_Vector4D();
109110 private final ENG_Vector4D awayFromLimitsPos = new ENG_Vector4D();
110111 private final ENG_Vector4D destination = new ENG_Vector4D(true);
111112 private final float updateInterval;
113+ private boolean rotationAwayFromLimitsCompleted = true;
114+ private boolean awayFromLimitsPosSet;
112115 // private float beginTime;
113116
114117 public AISystem(double interval) {
@@ -884,7 +887,9 @@
884887
885888 private void evadeLevelLimits(AIProperties aiProperties, EntityProperties entityProperties, ShipProperties shipProperties) {
886889 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) {
888893 aiProperties.setState(AIState.SEEK_CLOSEST_PLAYER);
889894 showAIStateChange(shipProperties, aiProperties);
890895 } else {
@@ -892,25 +897,40 @@
892897 // will end up with previous limits never going away since they are
893898 // only additive in EntityContactListener.
894899 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+
897913 // awayFromLimitsPos.addInPlace(entityProperties.getNode().getPosition());
898914 entityProperties.getNode().getPosition(currentPos);
899915 entityProperties.getNode().getLocalInverseZAxis(currentFrontVec);
900916 // entityProperties.getNode().getLocalYAxis(currentUpVec);
901917
902- // First slow down to 0 then rotate away.
903- entityProperties.setVelocity(0.0f);
918+ float angleBetween = currentFrontVec.angleBetween(awayFromLimitsPos);
919+
920+
904921 // ENG_Math.rotateTowardPositionDeg(awayFromLimitsPos, currentPos, currentFrontVec, currentUpVec, rotation, getRotationAngle(shipProperties));
905922 // 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);
910928
911929
912930
913931 if (angleBetween < ESCAPE_LEVEL_LIMITS_ANGLE) {
932+ rotationAwayFromLimitsCompleted = true;
933+ awayFromLimitsPosSet = false;
914934 // Also get to max speed
915935 changeVelocity(entityProperties, shipProperties, aiProperties, new VelocityChange(
916936 VELOCITY_CHANGE_NAME_ESCAPING_LIMITS,