finished basic wander with the cube. may need to edit once we have actual sprites..
This commit is contained in:
parent
10f20dd615
commit
a96bffe72a
53
Assets/AIScripts/wander.cs
Normal file
53
Assets/AIScripts/wander.cs
Normal 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;
|
||||
}
|
||||
|
||||
}
|
12
Assets/AIScripts/wander.cs.meta
Normal file
12
Assets/AIScripts/wander.cs.meta
Normal 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
BIN
Assets/AITestMap.unity
Normal file
Binary file not shown.
8
Assets/AITestMap.unity.meta
Normal file
8
Assets/AITestMap.unity.meta
Normal file
@ -0,0 +1,8 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 75885ae4c061d74438fe80c42c629773
|
||||
timeCreated: 1454125054
|
||||
licenseType: Free
|
||||
DefaultImporter:
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
9
Assets/Dusty Char.meta
Normal file
9
Assets/Dusty Char.meta
Normal file
@ -0,0 +1,9 @@
|
||||
fileFormatVersion: 2
|
||||
guid: b3ec1a33632cf4145be3ab233ee683d3
|
||||
folderAsset: yes
|
||||
timeCreated: 1454124956
|
||||
licenseType: Free
|
||||
DefaultImporter:
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
Binary file not shown.
Binary file not shown.
Reference in New Issue
Block a user