AI now uses NavMesh + tweaks

This commit is contained in:
darrelmarek 2017-09-18 12:43:50 -05:00
parent 62d26f586c
commit 810d76520c
5 changed files with 31 additions and 12 deletions

View file

@ -24,6 +24,7 @@ GameObject:
- component: {fileID: 23479163004144910}
- component: {fileID: 54771552521138126}
- component: {fileID: 114024861962930332}
- component: {fileID: 195715453755731944}
m_Layer: 0
m_Name: NPC
m_TagString: Untagged
@ -123,3 +124,24 @@ MonoBehaviour:
m_EditorClassIdentifier:
moveSpeed: 1.25
updateTime: 2
--- !u!195 &195715453755731944
NavMeshAgent:
m_ObjectHideFlags: 1
m_PrefabParentObject: {fileID: 0}
m_PrefabInternal: {fileID: 100100000}
m_GameObject: {fileID: 1057615597006810}
m_Enabled: 1
m_AgentTypeID: 0
m_Radius: 0.5
m_Speed: 1.5
m_Acceleration: 20
avoidancePriority: 50
m_AngularSpeed: 0
m_StoppingDistance: 0
m_AutoTraverseOffMeshLink: 1
m_AutoBraking: 1
m_AutoRepath: 1
m_Height: 1
m_BaseOffset: 0.5
m_WalkableMask: 4294967295
m_ObstacleAvoidanceType: 4

View file

@ -491,8 +491,8 @@ NavMeshAgent:
m_Enabled: 1
m_AgentTypeID: 0
m_Radius: 0.5
m_Speed: 1.3
m_Acceleration: 20
m_Speed: 1.5
m_Acceleration: 200
avoidancePriority: 50
m_AngularSpeed: 0
m_StoppingDistance: 0

View file

@ -1,17 +1,18 @@
using UnityEngine;
using System.Collections;
using UnityEngine.AI;
public class SimpleNPCBehavior : MonoBehaviour
{
public float moveSpeed;
public int updateTime;
private Rigidbody rigi;
private Vector3 target;
private NavMeshAgent agent;
void Start()
{
target.Set (4.0f - (8.0f * Random.value), 0.5f, 4.0f - (8.0f * Random.value));
rigi = GetComponent<Rigidbody>();
agent = GetComponent<NavMeshAgent> ();
}
void Update()
@ -22,10 +23,6 @@ public class SimpleNPCBehavior : MonoBehaviour
target.Set (4.0f - (8.0f * Random.value), 0.5f, 4.0f - (8.0f * Random.value));
}
// Check if NPC is at target and move there if not
if ((target.x - transform.position.x >= 0.01) || (target.x - transform.position.x <= -0.01) || (target.y - transform.position.y >= 0.01) || (target.y - transform.position.y <= -0.01))
transform.position += (target - transform.position).normalized * moveSpeed * Time.deltaTime;
rigi.velocity = Vector3.zero;
agent.destination = target;
}
}

View file

@ -6,10 +6,9 @@ public class SpyCameraController : MonoBehaviour {
private float camSens = 100.0f;
private float xRotation;
private Vector3 rotation;
void Start () {
rotation = new Vector3(0.0f, 0.0f, 0.0f);
xRotation = 0.0f;
}
void LateUpdate () {

View file

@ -35,6 +35,7 @@ GraphicsSettings:
- {fileID: 15106, guid: 0000000000000000f000000000000000, type: 0}
- {fileID: 10753, guid: 0000000000000000f000000000000000, type: 0}
- {fileID: 10770, guid: 0000000000000000f000000000000000, type: 0}
- {fileID: 16000, guid: 0000000000000000f000000000000000, type: 0}
m_PreloadedShaders: []
m_SpritesDefaultMaterial: {fileID: 10754, guid: 0000000000000000f000000000000000,
type: 0}