1
0

finished basic wander with the cube. may need to edit once we have actual sprites..

This commit is contained in:
CoryAlanDavis 2016-01-29 23:36:26 -05:00
parent 10f20dd615
commit a96bffe72a
7 changed files with 82 additions and 0 deletions

View File

@ -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<Rigidbody2D>();
SpriteRenderer mySprite = this.GetComponent<SpriteRenderer>();
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;
}
}

View File

@ -0,0 +1,12 @@
fileFormatVersion: 2
guid: fdfeca06308042847a6fb2cd3d736f58
timeCreated: 1454115530
licenseType: Free
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

BIN
Assets/AITestMap.unity Normal file

Binary file not shown.

View File

@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: 75885ae4c061d74438fe80c42c629773
timeCreated: 1454125054
licenseType: Free
DefaultImporter:
userData:
assetBundleName:
assetBundleVariant:

9
Assets/Dusty Char.meta Normal file
View File

@ -0,0 +1,9 @@
fileFormatVersion: 2
guid: b3ec1a33632cf4145be3ab233ee683d3
folderAsset: yes
timeCreated: 1454124956
licenseType: Free
DefaultImporter:
userData:
assetBundleName:
assetBundleVariant:

Binary file not shown.