Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class enemyMoveEngine : MonoBehaviour
- {
- public Vector3 playerPos;
- public float activeRange;
- public float fireRange;
- public GameObject ammoType;
- public float acceleration;
- public float delay;
- public float currentDelay;
- public float initialDrag;
- public float dragMultiplier;
- public float correctionBoostMulti;
- private Vector3 westEngine;
- private Vector3 eastEngine;
- private Vector3 southEngine;
- private Vector3 northEngine;
- public float correctionTimer;
- public float maxDrag;
- public float playerDistance;
- public float slowDistance;
- public float dragNorm;
- void Awake ()
- {
- rigidbody.drag = initialDrag;
- currentDelay = delay;
- westEngine = new Vector3(1,0,0);
- eastEngine = new Vector3(-1,0,0);
- northEngine = new Vector3(0,0,-1);
- southEngine = new Vector3(0,0,1);
- }
- void Update ()
- {
- playerDistance = Vector3.Distance (transform.position, playerPos);
- playerPos = GameObject.Find ("mainShip").transform.position - transform.position;
- currentDelay -= 1;
- fireEngines ();
- fireAtPlayer ();
- Debug.Log(rigidbody.drag);
- }
- void fireEngines ()
- {
- if (Vector3.Distance (transform.position, playerPos) <= activeRange) {
- if (playerPos.x > 0)
- {
- engineBoost(westEngine, correctionTimer);
- }
- if (playerPos.x <= 0)
- {
- engineBoost(eastEngine, correctionTimer);
- }
- if (playerPos.z > 0)
- {
- engineBoost(southEngine, correctionTimer);
- }
- if (playerPos.z <= 0)
- {
- engineBoost(northEngine, correctionTimer);
- }
- }
- }
- void fireAtPlayer ()
- {
- if (Vector3.Distance (transform.position, playerPos) <= activeRange && currentDelay <= 0)
- {
- currentDelay = delay;
- Instantiate (ammoType, transform.position, transform.rotation);
- }
- }
- float dragController(float dragVal)
- {
- float dragSet;
- if (playerDistance <= slowDistance)
- {
- dragSet = dragVal + (maxDrag - playerDistance);
- return dragSet;
- }
- else
- {
- return dragVal;
- }
- }
- void engineBoost(Vector3 direction, float correctionCount)
- {
- correctionCount -= 1;
- rigidbody.drag = dragController (initialDrag);
- rigidbody.AddForce((direction * acceleration) * correctionBoostMulti);
- if (correctionCount <=0)
- {
- rigidbody.AddForce((direction * acceleration));
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement