Add obstacle component for waiting client

This commit is contained in:
Antoine H 2021-01-04 15:34:54 +01:00
parent 772a7b665f
commit 8ba1513020
4 changed files with 64 additions and 7 deletions

View file

@ -14,6 +14,7 @@ GameObject:
- component: {fileID: 5304524770463492234}
- component: {fileID: 5304524770463492233}
- component: {fileID: 8842024822361446808}
- component: {fileID: -7733974610363878313}
m_Layer: 8
m_Name: Oldman
m_TagString: Usable
@ -119,7 +120,7 @@ BoxCollider2D:
m_IsTrigger: 1
m_UsedByEffector: 0
m_UsedByComposite: 0
m_Offset: {x: 0.0022666454, y: 0.25198603}
m_Offset: {x: 0.0008151531, y: 0.09807843}
m_SpriteTilingProperty:
border: {x: 0, y: 0, z: 0, w: 0}
pivot: {x: 0.5, y: 0}
@ -130,7 +131,7 @@ BoxCollider2D:
adaptiveTiling: 0
m_AutoTiling: 0
serializedVersion: 2
m_Size: {x: 0.44506907, y: 0.50397205}
m_Size: {x: 0.3086362, y: 0.19615686}
m_EdgeRadius: 0
--- !u!114 &5304524770463492233
MonoBehaviour:
@ -168,3 +169,19 @@ NavMeshAgent:
m_BaseOffset: 0.64
m_WalkableMask: 4294967295
m_ObstacleAvoidanceType: 4
--- !u!208 &-7733974610363878313
NavMeshObstacle:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 5304524770463492230}
m_Enabled: 0
serializedVersion: 3
m_Shape: 1
m_Extents: {x: 0.15, y: 0.1, z: 0.00001}
m_MoveThreshold: 0.1
m_Carve: 1
m_CarveOnlyStationary: 1
m_Center: {x: 0, y: 0.1, z: 0}
m_TimeToStationary: 0.5

View file

@ -3295,7 +3295,7 @@ Transform:
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 574958269}
m_LocalRotation: {x: -0, y: -0, z: -0, w: 1}
m_LocalPosition: {x: -6.62, y: -2, z: 2.5482712}
m_LocalPosition: {x: -6.64, y: -2.12, z: 2.5482712}
m_LocalScale: {x: 0.1, y: 0.1, z: 0.1}
m_Children: []
m_Father: {fileID: 1863361785}
@ -32709,12 +32709,34 @@ Transform:
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 1756509214}
m_LocalRotation: {x: -0, y: -0, z: -0, w: 1}
m_LocalPosition: {x: -3.34, y: -2.5, z: 2.5482712}
m_LocalPosition: {x: -3.4, y: -2.64, z: 2.5482712}
m_LocalScale: {x: 0.1, y: 0.1, z: 0.1}
m_Children: []
m_Father: {fileID: 1863361785}
m_RootOrder: 12
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
--- !u!1 &1810629360 stripped
GameObject:
m_CorrespondingSourceObject: {fileID: 5841415790350674203, guid: dc287deb81f09d8419a5051e1d177e74,
type: 3}
m_PrefabInstance: {fileID: 5841415791122168402}
m_PrefabAsset: {fileID: 0}
--- !u!208 &1810629367
NavMeshObstacle:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 1810629360}
m_Enabled: 0
serializedVersion: 3
m_Shape: 0
m_Extents: {x: 0.2, y: 0.2, z: 0.2}
m_MoveThreshold: 0.1
m_Carve: 0
m_CarveOnlyStationary: 1
m_Center: {x: 0, y: 0.2, z: 0}
m_TimeToStationary: 0.5
--- !u!1 &1863361784
GameObject:
m_ObjectHideFlags: 0

View file

@ -6,6 +6,7 @@ using UnityEngine.AI;
//Define the behavior of a client
[RequireComponent(typeof(Collider2D))]
[RequireComponent(typeof(NavMeshAgent))]
[RequireComponent(typeof(NavMeshObstacle))]
public class Client_controller : MonoBehaviour, IUsable
{
public float consumeTime = 3.0f; //Time to consume currentMug
@ -20,6 +21,20 @@ public class Client_controller : MonoBehaviour, IUsable
if (_availStatus.Contains(value))
_status = value;
Debug.Log(gameObject.name+" "+_status);
//Switch Agent to obstacle if waiting
if(value=="waiting")
{
agent.enabled = false;
navObstacle.enabled = true;
}
else
{
navObstacle.enabled = false;
agent.enabled = true;
}
// navObstacle.enabled = value=="waiting";
// agent.enabled = value!="waiting";
}
}
@ -30,6 +45,7 @@ public class Client_controller : MonoBehaviour, IUsable
//Navigation
Vector2 destination;
NavMeshAgent agent;
NavMeshObstacle navObstacle; //Obstacle for other agents
//Handle objects interactions w/ Workshop
//Return wether the object is taken from tavernkeeper
@ -76,10 +92,10 @@ public class Client_controller : MonoBehaviour, IUsable
if(gameObject.tag != "Usable")
Debug.LogWarning(gameObject.name+" tag should be set to 'Usable' to work properly");
status = "entering";
// Navigation //
agent = GetComponent<NavMeshAgent>();
navObstacle = GetComponent<NavMeshObstacle>();
//Prevent rotation of the ground at movement
agent.updateRotation = false;
agent.updateUpAxis = false;
@ -87,6 +103,8 @@ public class Client_controller : MonoBehaviour, IUsable
agent.destination = ClientManager.Instance.assignTarget();
//Assign Random priority to prevent two agent blocking each other
agent.avoidancePriority=Random.Range(0, 99);
status = "entering";
}
// Update is called once per frame

View file

@ -9,7 +9,7 @@ public sealed class ClientManager : MonoBehaviour
int nbMaxClients = 10;
bool clientSpawnReady = false;
float clientSpawnTimer = 0.5f; //Intial time before first spawn (pseudo-random after that)
float maxTimeNewClients = 10.0f;
float maxTimeNewClients = 2.0f;
string ClientRessourceFolder = "Clients";
private Object[] clients;