if i should script an AI script , what i should keep in mind to run the script
example : enemy (rotation,collision,crouych,jump
… thanks
if i should script an AI script , what i should keep in mind to run the script
example : enemy (rotation,collision,crouych,jump
… thanks
Finite State Machines (FSM)
http://ai-depot.com/FiniteStateMachines/
http://jessewarden.com/2012/07/finite-state-machines-in-game-development.html
http://www.voidinspace.com/2013/05/a-simple-finite-state-machine-with-c-delegates-in-unity/
He is showing you a link that describes what you are after.
To create a State machine you will want to use an enum
public enum States {Idle, Walk, Run, Crouch, Attack};
then from there you create an instance of this.
public States currentState;
from there you can now go ahead and create methods for each of these states.
public void Idle()
{
Debug.Log("We are Idle");
}
What i do is then have a method that allows me to switch or set states
public void SetState(States newState)
{
currentState = newState;
}
It’s then upto you how you want to enforce the checks on how to determine what state you are in.
For instance
public void Update()
{
if(Input.GetKey(KeyCode.W))
{
SetState(States.Walk);
}
}
I usually have a method that gets checked all the time
public void CheckStates()
{
switch(currentState)
case States.Walk:
{
Walk();
}break;
}
And have this in update although you will want to do more checks etc to filter out unnecessary checks and calls.
Hope this helps you out.
Cheers
John