Made in 2016
PedestrianAI
This is from the PedestrianAI Class currently all Ai related things are in the Update. At the time of making this I wasn't very good at cleaning up my scripts.void Update() { if(aim.looking == true) { StealNoticeVoid(); } if(Physics.Raycast(transform.position,transform.forward,out rayHit,10) && rayHit.collider.gameObject.tag == doorTag || Physics.Raycast(transform.position,transform.forward,out rayHit,2) && rayHit.collider.gameObject.tag == carTag) { if(rayHit.collider.gameObject.tag == doorTag) { rayHit.collider.GetComponent<Interactable>().Interacting(); } } else if(stationary == false && standStil == false) { characterAnimation.SetBool("Walking",true); navigator.SetDestination(checkPoints[currentCheckPoint].transform.position); if(myTransform.position.z == checkPoints[currentCheckPoint].transform.position.z && myTransform.position.x == checkPoints[currentCheckPoint].transform.position.x) { if(currentCheckPoint == checkPoints.Count - 1) { timer = stilStandingTime; standStil = true; characterAnimation.SetBool("Walking",false); } else { currentCheckPoint++; } } } else if(standStil == true) { if(timer <= 0) { standStil = false; currentCheckPoint = 0; } else { timer -= Time.deltaTime; } } }
CarAI
This is from the CarAI Class this also uses the unity navmesh to move.void Update() { navigator.SetDestination(checkPoints[currentCheckPoint].transform.position); Physics.Raycast(transform.position,transform.forward,out rayHit,raydistance); if(Physics.Raycast(transform.position,transform.forward,out rayHit,raydistance) && rayHit.collider.tag == carTag){ } else { if(myTransform.position.z >= checkPoints[currentCheckPoint].transform.position.z - missingAmount && myTransform.position.z <= checkPoints[currentCheckPoint].transform.position.z + missingAmount && myTransform.position.x >= checkPoints[currentCheckPoint].transform.position.x - missingAmount && myTransform.position.x <= checkPoints[currentCheckPoint].transform.position.x + missingAmount) { if(currentCheckPoint == checkPoints.Count - 1) { currentCheckPoint = 0; } else { currentCheckPoint++; } navigator.SetDestination(checkPoints[currentCheckPoint].transform.position); } } }
. Project LinkGithubGuard
This is part of the Guard class this class is used to move the guards and used to make the guards attack you when you steal.void Update() { if(aim.looking == true) { StealNoticeVoid(); } if(Physics.Raycast(transform.position,transform.forward,out rayHit,10) && rayHit.collider.gameObject.tag == doorTag || Physics.Raycast(transform.position,transform.forward,out rayHit,2) && rayHit.collider.gameObject.tag == carTag) { rayHit.collider.GetComponent<Interactable>().Interacting(); } else if(AIManager.wantedState == false) { if(stationary == false) { securityAnimator.SetBool("Walking",true); securityAnimator.SetBool("Wanted",false); navigator.speed = walkingSpeed; navigator.SetDestination(checkPoints[currentCheckPoint].transform.position); if(myTransform.position.z == checkPoints[currentCheckPoint].transform.position.z && myTransform.position.x == checkPoints[currentCheckPoint].transform.position.x) { if(currentCheckPoint == checkPoints.Count - 1) { currentCheckPoint = 0; } else { currentCheckPoint++; } } } else { transform.rotation = startingPosition.rotation; transform.position = startingPosition.position; securityAnimator.SetBool("Walking",false); securityAnimator.SetBool("Wanted",false); if(Random.Range(1,100) == 2) { securityAnimator.SetBool("Tip That Hat",true); securityAnimator.SetBool("Tip That Hat",false); } } } else { if(donut != null) { navigator.SetDestination(donut.transform.position); if(myTransform.position.z == donut.transform.position.z && myTransform.position.x == donut.transform.position.x) { securityAnimator.SetBool("Walking",false); securityAnimator.SetBool("Wanted",false); } } else { navigator.speed = runningSpeed; securityAnimator.SetBool("Wanted",true); navigator.SetDestination(player.position); } } }