diff --git a/Assets/AIScripts/wander.cs b/Assets/AIScripts/wander.cs new file mode 100644 index 0000000..3052d32 --- /dev/null +++ b/Assets/AIScripts/wander.cs @@ -0,0 +1,53 @@ +using UnityEngine; +using System.Collections; + +public class FlyingAI : MonoBehaviour { + + + + public LayerMask enemyMask; + public float speed = 1; + Rigidbody2D myBody; + Transform myTrans; + float myWidth, myHeight; + + // Use this for initialization + void Start() + { + myTrans = this.transform; + myBody = this.GetComponent(); + SpriteRenderer mySprite = this.GetComponent(); + myWidth = mySprite.bounds.extents.x; + myHeight = mySprite.bounds.extents.y; + } + + + // Update is called once per frame + void FixedUpdate () + { + + //check to see if there's ground in front of us before moving forward + Vector2 lineCastPos = myTrans.position.toVector2() - myTrans.right.toVector2() * myWidth + Vector2.up * myHeight; + lineCastPos.y = lineCastPos.y - (myHeight * 1.2f); + Debug.DrawLine(lineCastPos, lineCastPos + Vector2.down); + bool isGrounded = Physics2D.Linecast(lineCastPos, lineCastPos + Vector2.down, enemyMask); + Debug.DrawLine(lineCastPos, lineCastPos - myTrans.right.toVector2() * 0.05f); + bool isBlocked = Physics2D.Linecast(lineCastPos, lineCastPos - myTrans.right.toVector2() * 0.05f, enemyMask); + + //if no ground turn around + if(!isGrounded || isBlocked) + { + Vector3 currentRot = myTrans.eulerAngles; + currentRot.y += 180; + myTrans.eulerAngles = currentRot; + } + + + + //always move forward + Vector2 myVel = myBody.velocity; + myVel.x = -myTrans.right.x * speed; + myBody.velocity = myVel; + } + +} diff --git a/Assets/AIScripts/wander.cs.meta b/Assets/AIScripts/wander.cs.meta new file mode 100644 index 0000000..3ba600e --- /dev/null +++ b/Assets/AIScripts/wander.cs.meta @@ -0,0 +1,12 @@ +fileFormatVersion: 2 +guid: fdfeca06308042847a6fb2cd3d736f58 +timeCreated: 1454115530 +licenseType: Free +MonoImporter: + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/AITestMap.unity b/Assets/AITestMap.unity new file mode 100644 index 0000000..bf00ffa Binary files /dev/null and b/Assets/AITestMap.unity differ diff --git a/Assets/AITestMap.unity.meta b/Assets/AITestMap.unity.meta new file mode 100644 index 0000000..fa936e9 --- /dev/null +++ b/Assets/AITestMap.unity.meta @@ -0,0 +1,8 @@ +fileFormatVersion: 2 +guid: 75885ae4c061d74438fe80c42c629773 +timeCreated: 1454125054 +licenseType: Free +DefaultImporter: + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/Dusty Char.meta b/Assets/Dusty Char.meta new file mode 100644 index 0000000..7540b9d --- /dev/null +++ b/Assets/Dusty Char.meta @@ -0,0 +1,9 @@ +fileFormatVersion: 2 +guid: b3ec1a33632cf4145be3ab233ee683d3 +folderAsset: yes +timeCreated: 1454124956 +licenseType: Free +DefaultImporter: + userData: + assetBundleName: + assetBundleVariant: diff --git a/ProjectSettings/ProjectSettings.asset b/ProjectSettings/ProjectSettings.asset index 654f2ec..0128a24 100644 Binary files a/ProjectSettings/ProjectSettings.asset and b/ProjectSettings/ProjectSettings.asset differ diff --git a/ProjectSettings/TagManager.asset b/ProjectSettings/TagManager.asset index ad3b22f..e1dad5b 100644 Binary files a/ProjectSettings/TagManager.asset and b/ProjectSettings/TagManager.asset differ