Advertisement
Guest User

Untitled

a guest
Sep 2nd, 2014
220
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.28 KB | None | 0 0
  1.  
  2. public class enemyMoveEngine : MonoBehaviour
  3. {
  4.  
  5.     public Vector3 playerPos;
  6.     public float activeRange;
  7.     public float fireRange;
  8.     public GameObject ammoType;
  9.     public float acceleration;
  10.     public float delay;
  11.     public float currentDelay;
  12.     public float initialDrag;
  13.     public float dragMultiplier;
  14.     public float correctionBoostMulti;
  15.     private Vector3 westEngine;
  16.     private Vector3 eastEngine;
  17.     private Vector3 southEngine;
  18.     private Vector3 northEngine;
  19.     public float correctionTimer;
  20.     public float maxDrag;
  21.     public float playerDistance;
  22.     public float slowDistance;
  23.     public float dragNorm;
  24.  
  25.     void Awake ()
  26.     {
  27.         rigidbody.drag = initialDrag;
  28.         currentDelay = delay;
  29.         westEngine = new Vector3(1,0,0);
  30.         eastEngine = new Vector3(-1,0,0);
  31.         northEngine = new Vector3(0,0,-1);
  32.         southEngine = new Vector3(0,0,1);
  33.     }
  34.  
  35.     void Update ()
  36.     {
  37.         playerDistance = Vector3.Distance (transform.position, playerPos);
  38.         playerPos = GameObject.Find ("mainShip").transform.position - transform.position;
  39.         currentDelay -= 1;
  40.         fireEngines ();
  41.         fireAtPlayer ();
  42.         Debug.Log(rigidbody.drag);
  43.     }
  44.  
  45.     void fireEngines ()
  46.     {
  47.         if (Vector3.Distance (transform.position, playerPos) <= activeRange) {
  48.             if (playerPos.x > 0)
  49.             {
  50.                 engineBoost(westEngine, correctionTimer);
  51.             }
  52.             if (playerPos.x <= 0)
  53.             {
  54.                 engineBoost(eastEngine, correctionTimer);
  55.             }
  56.             if (playerPos.z > 0)
  57.             {
  58.                 engineBoost(southEngine, correctionTimer);
  59.             }
  60.             if (playerPos.z <= 0)
  61.             {
  62.                 engineBoost(northEngine, correctionTimer);
  63.             }
  64.         }
  65.     }
  66.  
  67.     void fireAtPlayer ()
  68.     {
  69.         if (Vector3.Distance (transform.position, playerPos) <= activeRange && currentDelay <= 0)
  70.         {
  71.             currentDelay = delay;
  72.             Instantiate (ammoType, transform.position, transform.rotation);
  73.         }
  74.     }
  75.  
  76.     float dragController(float dragVal)
  77.     {
  78.         float dragSet;
  79.         if (playerDistance <= slowDistance)
  80.         {
  81.             dragSet = dragVal + (maxDrag - playerDistance);
  82.             return dragSet;
  83.         }
  84.         else
  85.         {
  86.             return dragVal;
  87.         }
  88.     }
  89.     void engineBoost(Vector3 direction, float correctionCount)
  90.     {
  91.         correctionCount -= 1;
  92.  
  93.         rigidbody.drag = dragController (initialDrag);
  94.         rigidbody.AddForce((direction * acceleration) * correctionBoostMulti);
  95.         if (correctionCount <=0)
  96.         {
  97.             rigidbody.AddForce((direction * acceleration));
  98.         }
  99.     }
  100. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement