Created
September 16, 2021 09:17
-
-
Save simoninithomas/5c95ae846effe846b8a5dd47aea0e32b to your computer and use it in GitHub Desktop.
JammoBehavior_Tutorial Part 2
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
private void Update() | |
{ | |
// Here's the State Machine, where given its current state, the agent will act accordingly | |
switch(state) | |
{ | |
default: | |
case State.Idle: | |
Debug.Log("STATE IDLE"); | |
break; | |
case State.Hello: | |
agent.SetDestination(playerPosition.position); | |
if (Vector3.Distance(transform.position, playerPosition.position) < reachedPositionDistance) | |
{ | |
RotateTo(); | |
anim.SetBool("hello", true); | |
state = State.Idle; | |
} | |
break; | |
case State.Happy: | |
agent.SetDestination(playerPosition.position); | |
if (Vector3.Distance(transform.position, playerPosition.position) < reachedPositionDistance) | |
{ | |
RotateTo(); | |
anim.SetBool("happy", true); | |
state = State.Idle; | |
} | |
break; | |
case State.Puzzled: | |
Debug.Log("CASE STATE PUZZLED"); | |
agent.SetDestination(playerPosition.position); | |
if (Vector3.Distance(transform.position, playerPosition.position) < reachedPositionDistance) | |
{ | |
RotateTo(); | |
anim.SetBool("puzzled", true); | |
state = State.Idle; | |
} | |
break; | |
case State.MoveTo: | |
agent.SetDestination(goalObject.transform.position); | |
if (Vector3.Distance(transform.position, goalObject.transform.position) < reachedPositionDistance) | |
{ | |
state = State.Idle; | |
} | |
break; | |
case State.BringObject: | |
// First move to the object | |
agent.SetDestination(goalObject.transform.position); | |
if (Vector3.Distance(transform.position, goalObject.transform.position) < reachedObjectPositionDistance) | |
{ | |
Grab(goalObject); | |
state = State.BringObjectToPlayer; | |
} | |
break; | |
case State.BringObjectToPlayer: | |
agent.SetDestination(playerPosition.transform.position); | |
if (Vector3.Distance(transform.position, playerPosition.transform.position) < reachedObjectPositionDistance) | |
{ | |
Drop(goalObject); | |
state = State.Idle; | |
} | |
break; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment