//function to execute in stun state, containes transitions, and decrements stun timer void stun() { posTimer = 30; posTimer2 = 25; //decrement stun timer stunTimer -= Time.deltaTime; //if enough timer has passed transition to appropiate state if (stunTimer <= 0) { animState = OniAnim.Idle; seen = false; seen = SeeObject(PlayerObject, LevelMask, home); foundFootprint = SeeFootprint(allNodes, LevelMask, home); if (seen) { State = OniState.Chase; return; } else if (foundFootprint != null && awake == true) { nextFootprint = foundFootprint; State = OniState.Follow; return; } else { State = OniState.Idle; return; } } }
void animRun() { if (agent.velocity.magnitude > 5.5) { anim.SetInteger("State", 2); } else { animState = OniAnim.Walk; } }
void animWalk() { if (agent.velocity.magnitude > 0.5) { anim.SetInteger("State", 1); } else { animState = OniAnim.Idle; } }
void animIdle() { if (agent.velocity.magnitude < 0.5) { anim.SetInteger("State", 0); } else { animState = OniAnim.Walk; } }
//if oni recieves stun message execute the following code void Stun() { //transition to stun state State = OniState.Stun; animState = OniAnim.Stunned; //set timer stunTimer = 15; //stop motion agent.SetDestination(transform.position); //stun has priority over fleeing inu fleeingInu = false; }
//function called at initialization of oni void Start() { //intialize variables anim = GetComponentInChildren <Animator>(); rb = GetComponent <Rigidbody>(); home = gameObject.transform.position; startingRotation = gameObject.transform.rotation; actorID = GetComponent <Actor>(); State = OniState.Idle; animState = OniAnim.Idle; awake = false; PlayerObject = GameObject.FindGameObjectWithTag("Player"); oldPosition = home; posTimer = 6; posTimer2 = 23; root = MazeGenerator.getSectionBasedOnLocation(home); if (root != null) { nodes = MazeGenerator.GetIntersectionNodes(root); } fleeTimer = 5; fleeingInu = false; currentNode = StartingNode; //find home node based on location, a nodes location is its individual values - 8 and then divided by 6 column = (int)((home.x - 8) / 6); row = (int)((home.z - 8) / 6); //print("oni home: x " + home.x + " col: " + column + " z: " + home.z + " row: " + row); allNodes = MazeGenerator.nodesInSection(root); foreach (MazeNode n in allNodes) { if (n.Col == column && n.Row == row) { homeNode = n; } } floor = homeNode.Floor; agent = GetComponent <NavMeshAgent>(); //turn of default nav mesh movement as it doesn't include gravity agent.updatePosition = false; agent.updateRotation = true; agent.nextPosition = transform.position; //transform.position = agent.nextPosition; agent.Warp(transform.position); //print("trans" + transform.position); //print("nav" + agent.nextPosition); }