From e3d888f757e72fc5eb6b0b39ad64f9784ceaa3ef Mon Sep 17 00:00:00 2001 From: "j.mei7" Date: Wed, 16 Mar 2022 19:47:40 +0100 Subject: [PATCH] better pathfinding --- Assets/Scripts/Pathfinding/Pathfinding.cs | 8 ++++---- Assets/Scripts/Person/Person.cs | 9 +++++++-- 2 files changed, 11 insertions(+), 6 deletions(-) diff --git a/Assets/Scripts/Pathfinding/Pathfinding.cs b/Assets/Scripts/Pathfinding/Pathfinding.cs index c911acf..b58420f 100644 --- a/Assets/Scripts/Pathfinding/Pathfinding.cs +++ b/Assets/Scripts/Pathfinding/Pathfinding.cs @@ -105,17 +105,17 @@ public class Pathfinding { // Left neighbourList.Add(GetNode(currentNode.x - 1, currentNode.y)); // Left Down - if (currentNode.y - 1 >= 0) neighbourList.Add(GetNode(currentNode.x - 1, currentNode.y - 1)); + // if (currentNode.y - 1 >= 0) neighbourList.Add(GetNode(currentNode.x - 1, currentNode.y - 1)); // Left Up - if (currentNode.y + 1 < grid.GetHeight()) neighbourList.Add(GetNode(currentNode.x - 1, currentNode.y + 1)); + // if (currentNode.y + 1 < grid.GetHeight()) neighbourList.Add(GetNode(currentNode.x - 1, currentNode.y + 1)); } if (currentNode.x + 1 < grid.GetWidth()) { // Right neighbourList.Add(GetNode(currentNode.x + 1, currentNode.y)); // Right Down - if (currentNode.y - 1 >= 0) neighbourList.Add(GetNode(currentNode.x + 1, currentNode.y - 1)); + // if (currentNode.y - 1 >= 0) neighbourList.Add(GetNode(currentNode.x + 1, currentNode.y - 1)); // Right Up - if (currentNode.y + 1 < grid.GetHeight()) neighbourList.Add(GetNode(currentNode.x + 1, currentNode.y + 1)); + // if (currentNode.y + 1 < grid.GetHeight()) neighbourList.Add(GetNode(currentNode.x + 1, currentNode.y + 1)); } // Down if (currentNode.y - 1 >= 0) neighbourList.Add(GetNode(currentNode.x, currentNode.y - 1)); diff --git a/Assets/Scripts/Person/Person.cs b/Assets/Scripts/Person/Person.cs index cbcc2c0..625153a 100644 --- a/Assets/Scripts/Person/Person.cs +++ b/Assets/Scripts/Person/Person.cs @@ -145,15 +145,20 @@ public class Person : MonoBehaviour void Work() { + if (status != PersonStatus.WORK) + movement.SetTarget(workplace.transform.position); status = PersonStatus.WORK; - movement.SetTarget(workplace.transform.position); + } void Sleep() { + if(status != PersonStatus.SLEEP) + movement.SetTarget(house.transform.position); + status = PersonStatus.SLEEP; Debug.Log(house.transform.position); - movement.SetTarget(house.transform.position); + } void SetBehaivorDateTimes()