diff ai.d @ 14:af1e8620f027

fixed steering
author zzzzrrr <mason.green@gmail.com>
date Mon, 23 Mar 2009 14:06:47 -0400
parents e1004697cae1
children 8e6a9e390cba
line wrap: on
line diff
--- a/ai.d	Mon Mar 23 08:02:23 2009 -0400
+++ b/ai.d	Mon Mar 23 14:06:47 2009 -0400
@@ -33,7 +33,7 @@
 import tango.io.Stdout : Stdout;
 import tango.math.Math : atan2, abs, PI;
 
-import blaze.common.bzMath: bzVec2;
+import blaze.common.bzMath: bzVec2, bzClamp;
 import openmelee.steer : Steer;
 import openmelee.ship : Ship;
 
@@ -42,7 +42,7 @@
 
 	Steer steer;
 	Ship ship;
-	float maxPredictionTime = 0.5f;
+	float maxPredictionTime = 0.1f;
 	
 	this(Ship ship) {
 		this.ship = ship;
@@ -51,40 +51,36 @@
 	
 	void move(Ship enemy) {
 	    
+        // Ver stupid, elementary AI so far...
+        
 	    steer.update();
 	    bzVec2 st;
 	    st = steer.steerForPursuit(enemy.state, maxPredictionTime);
-	    
 	    ship.state.target = st;
+        st = ship.rBody.localPoint(st);
+        float x = st.x;
+		float y = st.y;
+        st = -bzVec2(y,-x);
         float angle = atan2(st.x, st.y);
 		
-		Stdout("Target angle: ")(angle).newline;
-		
-		float x = ship.state.forward.x;
-		float y = ship.state.forward.y;
-		float angle2 = atan2(x,y);
-		
-        
-		float rel = angle2 - angle;
-		
-		if(abs(rel) > PI/8) {
-			if(angle < angle2) {
-				ship.turnLeft();
-				ship.state.turn = true;
-			} else {
-				ship.state.turn = true;
-				ship.turnRight();
-			}
+		if(abs(angle) > 0.05) {
+            if(!ship.state.turn) {
+                if(st.x >= 0) {
+                    ship.turnRight();
+                    ship.state.turn = true;
+                } else {
+                    ship.state.turn = true;
+                    ship.turnLeft();
+                }
+           }
 		} else {
 			ship.rBody.angularVelocity = 0.0f;
 			ship.state.turn = false;
 		}
 		
-		ship.state.enemyAngle = rel;
-		
 		float range = (ship.state.position - enemy.state.position).length; 
-		if(range > 20 && !ship.state.turn) {
-			//ship.thrust();
+		if(range > 10 && abs(angle) < PI/4) {
+			ship.thrust();
 		}
     }