Browse Source

Fix conditions bug

main
parent
commit
13ac873143
4 changed files with 38 additions and 21 deletions
  1. +24
    -18
      Assets/Scenes/Main.unity
  2. +3
    -1
      Assets/StateStuff/Conditions/OnNavigationEndCondition.cs
  3. +9
    -2
      Assets/StateStuff/StateMachine.cs
  4. +2
    -0
      Assets/StateStuff/States/DecideWhereToGo.cs

+ 24
- 18
Assets/Scenes/Main.unity View File

@@ -399,6 +399,7 @@ GameObject:
- component: {fileID: 923169546}
- component: {fileID: 923169545}
- component: {fileID: 923169547}
- component: {fileID: 923169548}
m_Layer: 0
m_Name: Agent
m_TagString: Untagged
@@ -449,13 +450,13 @@ Transform:
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 923169541}
m_LocalRotation: {x: 0, y: 0, z: 0, w: 1}
m_LocalPosition: {x: 0.25, y: 0.3, z: -2.75}
m_LocalRotation: {x: -0, y: -0, z: -0, w: 1}
m_LocalPosition: {x: -3.49, y: 0, z: 3.57}
m_LocalScale: {x: 1, y: 1, z: 1}
m_Children:
- {fileID: 546327654}
m_Father: {fileID: 0}
m_RootOrder: 3
m_RootOrder: 4
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
--- !u!114 &923169545
MonoBehaviour:
@@ -491,6 +492,12 @@ MonoBehaviour:
transitions:
- state: {fileID: 923169545}
condition: {fileID: 11400000, guid: ea14b43f326ad1649b2504a37f41d751, type: 2}
- state: {fileID: 923169548}
condition: {fileID: 11400000, guid: ea14b43f326ad1649b2504a37f41d751, type: 2}
- state: {fileID: 923169548}
transitions:
- state: {fileID: 923169547}
condition: {fileID: 11400000, guid: 099c7b16d7d1d774a8d70c36624cbb22, type: 2}
initialState: {fileID: 923169547}
currentState: {fileID: 0}
--- !u!114 &923169547
@@ -505,6 +512,19 @@ MonoBehaviour:
m_Script: {fileID: 11500000, guid: c787265fe031b8f4cb1bdbf86abd8b79, type: 3}
m_Name:
m_EditorClassIdentifier:
--- !u!114 &923169548
MonoBehaviour:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 923169541}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: f8324af9f292d3d479a736708998291b, type: 3}
m_Name:
m_EditorClassIdentifier:
home: {fileID: 1221565582}
--- !u!1 &963194225
GameObject:
m_ObjectHideFlags: 0
@@ -713,7 +733,6 @@ GameObject:
- component: {fileID: 1221565582}
- component: {fileID: 1221565581}
- component: {fileID: 1221565580}
- component: {fileID: 1221565579}
m_Layer: 0
m_Name: Home
m_TagString: Untagged
@@ -721,19 +740,6 @@ GameObject:
m_NavMeshLayer: 0
m_StaticEditorFlags: 0
m_IsActive: 1
--- !u!135 &1221565579
SphereCollider:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 1221565578}
m_Material: {fileID: 0}
m_IsTrigger: 0
m_Enabled: 1
serializedVersion: 2
m_Radius: 0.5
m_Center: {x: 0, y: 0, z: 0}
--- !u!23 &1221565580
MeshRenderer:
m_ObjectHideFlags: 0
@@ -793,7 +799,7 @@ Transform:
m_LocalScale: {x: 1, y: 1, z: 1}
m_Children: []
m_Father: {fileID: 0}
m_RootOrder: 4
m_RootOrder: 3
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
--- !u!4 &1221604627 stripped
Transform:


+ 3
- 1
Assets/StateStuff/Conditions/OnNavigationEndCondition.cs View File

@@ -7,13 +7,15 @@ public class OnNavigationEndCondition : Condition
{

Wanderer wanderer;
float initTime;

public override void Initialize(GameObject agent){
wanderer = agent.GetComponent<Wanderer>();
initTime = Time.time;
}

public override bool TransitionActive()
{
return !wanderer.isNavigating;
return !wanderer.isNavigating && Time.time>initTime+0.25f;
}
}

+ 9
- 2
Assets/StateStuff/StateMachine.cs View File

@@ -39,6 +39,7 @@ public class StateMachine : MonoBehaviour
currentState = transition.state;
currentState.EnterState();
InitializeConditions();
break;
}
}
currentState.UpdateState();
@@ -46,9 +47,15 @@ public class StateMachine : MonoBehaviour

void InitializeConditions(){
Transitions currentTransitions = GetCurrentTransitions();
foreach (Transition transition in currentTransitions.transitions){
transition.condition.Initialize(this.gameObject);
List<Transition> lTransitions = currentTransitions.transitions;
for (int i = 0; i<lTransitions.Count; i++){
Transition t = lTransitions[i];
Condition cond = Instantiate(t.condition);
cond.Initialize(this.gameObject);
t.condition = cond;
lTransitions[i] = t;
}
currentTransitions.transitions = lTransitions;
}

Transitions GetCurrentTransitions(){


+ 2
- 0
Assets/StateStuff/States/DecideWhereToGo.cs View File

@@ -36,6 +36,8 @@ public class DecideWhereToGo : State
Vector3 point;
if (GetRandomPointOnNavMesh(out point)){
wanderer.SetDestination(point);
} else {
Debug.Log("Couldn't find point?");
}
}



Loading…
Cancel
Save