From 10f20dd615afcee91e4eb4580ada5d4db9c6d30c Mon Sep 17 00:00:00 2001 From: CoryAlanDavis Date: Fri, 29 Jan 2016 22:22:29 -0500 Subject: [PATCH] Started on basic AI -Cory --- Assets/AIScripts.meta | 9 ++++ Assets/AIScripts/ExtensionMethods.cs | 10 ++++ Assets/AIScripts/ExtensionMethods.cs.meta | 12 +++++ Assets/AIScripts/FlyingAI.cs | 49 +++++++++++++++++++ Assets/AIScripts/FlyingAI.cs.meta | 12 +++++ Assets/Sprites.meta | 9 ++++ Assets/Sprites/YellowSquare.png | Bin 0 -> 86703 bytes Assets/Sprites/YellowSquare.png.meta | 57 ++++++++++++++++++++++ 8 files changed, 158 insertions(+) create mode 100644 Assets/AIScripts.meta create mode 100644 Assets/AIScripts/ExtensionMethods.cs create mode 100644 Assets/AIScripts/ExtensionMethods.cs.meta create mode 100644 Assets/AIScripts/FlyingAI.cs create mode 100644 Assets/AIScripts/FlyingAI.cs.meta create mode 100644 Assets/Sprites.meta create mode 100644 Assets/Sprites/YellowSquare.png create mode 100644 Assets/Sprites/YellowSquare.png.meta diff --git a/Assets/AIScripts.meta b/Assets/AIScripts.meta new file mode 100644 index 0000000..aa14b2f --- /dev/null +++ b/Assets/AIScripts.meta @@ -0,0 +1,9 @@ +fileFormatVersion: 2 +guid: 4c44a4c31a986904d81036cf9e73b54e +folderAsset: yes +timeCreated: 1454116885 +licenseType: Free +DefaultImporter: + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/AIScripts/ExtensionMethods.cs b/Assets/AIScripts/ExtensionMethods.cs new file mode 100644 index 0000000..0391704 --- /dev/null +++ b/Assets/AIScripts/ExtensionMethods.cs @@ -0,0 +1,10 @@ +using UnityEngine; +using System.Collections; + +public static class ExtensionMethods +{ + public static Vector2 toVector2(this Vector3 vec3) + { + return new Vector2(vec3.x, vec3.y); + } +} diff --git a/Assets/AIScripts/ExtensionMethods.cs.meta b/Assets/AIScripts/ExtensionMethods.cs.meta new file mode 100644 index 0000000..1746c3c --- /dev/null +++ b/Assets/AIScripts/ExtensionMethods.cs.meta @@ -0,0 +1,12 @@ +fileFormatVersion: 2 +guid: 9a2a3bd0eab8bd44a8b62c66b491b74f +timeCreated: 1454122812 +licenseType: Free +MonoImporter: + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/AIScripts/FlyingAI.cs b/Assets/AIScripts/FlyingAI.cs new file mode 100644 index 0000000..0419bb7 --- /dev/null +++ b/Assets/AIScripts/FlyingAI.cs @@ -0,0 +1,49 @@ +using UnityEngine; +using System.Collections; + +public class FlyingAI : MonoBehaviour { + + + + public LayerMask enemyMask; + public float speed = 1; + Rigidbody2D myBody; + Transform myTrans; + float myWidth; + + // Use this for initialization + void Start() + { + myTrans = this.transform; + myBody = this.GetComponent(); + myWidth = this.GetComponent().bounds.extents.x; + } + + + // 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 - myTrans.right * myWidth; + Debug.DrawLine(lineCastPos, lineCastPos + Vector2.down); + bool isGrounded = Physics2D.Linecast(lineCastPos, lineCastPos + Vector2.down, enemyMask); + Debug.DrawLine(lineCastPos, lineCastPos + Vector2.down); + //bool isBlocked = Physics2D.Linecast(lineCastPos, lineCastPos - myTrans.right.toVector2(), enemyMask); + + //if no ground turn around + if(!isGrounded) + { + 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/FlyingAI.cs.meta b/Assets/AIScripts/FlyingAI.cs.meta new file mode 100644 index 0000000..3ba600e --- /dev/null +++ b/Assets/AIScripts/FlyingAI.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/Sprites.meta b/Assets/Sprites.meta new file mode 100644 index 0000000..05c8277 --- /dev/null +++ b/Assets/Sprites.meta @@ -0,0 +1,9 @@ +fileFormatVersion: 2 +guid: 6f492c3af74d41b4297e290ed0fb7af6 +folderAsset: yes +timeCreated: 1454116896 +licenseType: Free +DefaultImporter: + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/Sprites/YellowSquare.png b/Assets/Sprites/YellowSquare.png new file mode 100644 index 0000000000000000000000000000000000000000..01db18ae747a40f1cca2ba20bdf67ee3d31f47a7 GIT binary patch literal 86703 zcmeI*c{J5)-^cNv$UIesBpo72#ta?vu#K5Ag*2eDm4tFKm9}K64oPK-G{~%?NGK#k zh|07L6_Omfk0Hu*U%z^u`+82#KhN{WeeQq0do9`2+PhxsjgPgipQ5*08gsF)VJ8TJ z%hbfch9Fi&kuR*v(0kgx@m@u**nCW!juC{MIQha5kfC#&AlR)AQYhQEdwBbKAM^0` z5jCYyM178WyB|D!fFJ_8Q*Ehswj%;sGksI~W>K_DX5KdZtfDsh=V*L!lG0*qyxXG0 zu6OZUSFJEKWD>4Vk7A68p`GWqmf<|h-pMj3b|WV2X4Kh+xp%=gJ=@D?J~S;p=+GX{ zn@lZgVX0*0ykeqctwQ6>)?c^cZCG7R?Ylua-B5N3AA*;)XusI81#t#qHbhf%^ZH7b z#{@&bD-Kqo(jui&VQu6R&nNw)T@17{43&OyznZbq_z2yg82#IXt`P$*HBr)*NM|Bk z8uz&k5Zh%5myM@Bydr3+vq`}Wg!3gaeunfoLUh%EC%F5n%OMp8+I znxztIhM~@^vc4=14sz?HnoR{a^QpQnb4}Kjs}4*O+7hbF^LFwDL8Qm=qkrw>LO?Tj zL36WeOfmOf*-uZHm)5(v4J;0|_f15ey zUdW^SfJh(dc9`@bZ49qpDDCPR8XWB0R-^Ci+Td_yjov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