// Use this for initialization private void Start() { // Component reference assignments dependant on other scripts tankTf = tankData.tankTf; mover = tankData.tankMover; vision = controller.vision; hearing = controller.hearing; }
// Use this for initialization void Start() { rend = this.GetComponent <SpriteRenderer>(); vision = transform.parent.GetComponentInChildren <AIVision>(); startRotation = transform.rotation.eulerAngles; }
/* Private Variables */ private void Awake() { // Component reference assignments tankData = this.gameObject.GetComponent <TankData>(); behaviors = this.gameObject.GetComponent <AIBehaviors>(); vision = this.gameObject.GetComponent <AIVision>(); hearing = this.gameObject.GetComponent <AIHearing>(); roomData = this.gameObject.GetComponentInParent <RoomData>(); }
public void OnPreStarted() { movement = GetComponent <Movement>(); animator = GetComponent <CharacterAnimator>(); vision = GetComponent <AIVision>(); healthManager = GetComponent <HealthManager>(); healthManager.OnDied += Die; }
public override void OnStateEnter() { AIVision aIVision = owner.PreviousState as AIVision; if (aIVision == null || !aIVision.CurrentTarget) { owner.SwitchState(next); return; } agent.isStopped = false; target = aIVision.CurrentTarget; agent.SetDestination(target.position); }
[HideInInspector] public RaycastHit obstacleHit; // Raycast hit for obstacles (Includes the arena and other enemy tanks) public override void Start() { base.Start(); characterController = GetComponent <CharacterController>(); enemyData = GetComponent <EnemyData>(); //ptf = GameManager.instance.playerTank.GetComponent<Transform>(); aiVision = GetComponentInChildren <AIVision>(); aiHearing = GetComponentInChildren <AIHearing>(); // Set investigateTime, searchTime and waitTime to the default values saved in Enemy Data investigateTime = enemyData.investigateDuration; searchTime = enemyData.searchDuration; waitTime = enemyData.waitDuration; alertTime = enemyData.alertDuration; }
public override void OnStateEnter() { AIVision aIVision = owner.PreviousState as AIVision; if (aIVision == null) { OnDestinationReached.Raise(); return; } agent.isStopped = false; targetDestination = aIVision.CurrentTarget.transform.position; agent.SetDestination(targetDestination); return; }
public override float ReturnWeight(GameObject owner) { //base.OnExecuteThought(owner); AIVision vision = owner.GetComponent <AIVision>(); if (vision.target == null) { // have no target then we are 25% to be idleing. This is a bit basic but works in the example. return(25f); } else { // Have target so no longer idle. return(100f); } }
private void OnSceneGUI() { AIVision vision = (AIVision)target; Handles.color = Color.green; Handles.DrawWireArc(vision.transform.position, Vector3.forward, Vector3.up, 360, vision.viewRadius); Vector3 viewAngleA = vision.DirectionFromAngle(-vision.viewAngle / 2, false); Vector3 viewAngleB = vision.DirectionFromAngle(vision.viewAngle / 2, false); Handles.DrawLine(vision.transform.position, vision.transform.position + viewAngleA * vision.viewRadius); Handles.DrawLine(vision.transform.position, vision.transform.position + viewAngleB * vision.viewRadius); Handles.color = Color.magenta; foreach (var foundTarget in vision.foundTargets) { Handles.DrawLine(vision.transform.position, foundTarget.position); } }
// Use this for initialization void Start() { SE = GetComponent <StudioEventEmitter>(); animator = this.GetComponent <Animator>(); gun = this.transform.GetComponentInChildren <Gun>(); aiVision = this.transform.GetComponentInChildren <AIVision>(); ai = this.GetComponent <AI>(); levelGenerator = GameObject.Find("LevelGenerator").GetComponent <LevelGenerator>(); ai.target = GameObject.FindWithTag("Player").transform; startIdleTime = idleTime; startPatrolTime = patrolTime; if (gameObject.tag == "Enemy") { Decision(); } }
// Shows a visual representation of the size of this tank's cone of vision private void OnDrawGizmosSelected() { TankData tankData = this.gameObject.GetComponent <TankData>(); Transform tankTf = this.gameObject.GetComponent <Transform>(); AIVision vision = this.gameObject.GetComponent <AIVision>(); // Previews the tank's vision distance Gizmos.color = Color.red; Gizmos.DrawLine(tankTf.position, tankTf.position + tankTf.forward * visionDistance); Gizmos.DrawWireSphere(tankTf.position, hearingRadius); // Previews the tank's vision angle Gizmos.color = Color.yellow; Gizmos.DrawLine(tankTf.position, tankTf.position + vision.VectorFromForward(-visionAngle / 2) * visionAngle); Gizmos.DrawLine(tankTf.position, tankTf.position + vision.VectorFromForward(visionAngle / 2) * visionAngle); // Previews the tank's obstacle checking Gizmos.color = Color.white; Gizmos.DrawLine(tankData.leftRaycastTf.position, tankData.leftRaycastTf.position + tankData.leftRaycastTf.forward * (visionDistance * avoidanceRange)); Gizmos.DrawLine(tankData.rightRaycastTf.position, tankData.rightRaycastTf.position + tankData.rightRaycastTf.forward * (visionDistance * avoidanceRange)); Gizmos.DrawLine(tankData.originRayCastTf.position, tankData.originRayCastTf.position + tankData.originRayCastTf.forward * (visionDistance * avoidanceRange)); }
public void Setup(HumanSheet humanSheetIn, bool isZombie, GameObject squadDeployment = null) { this.humanSheet = humanSheetIn; this.isZombie = isZombie; animator = transform.parent.GetComponent <Animator> (); stateMachine = transform.parent.GetComponent <AnimationStateMachine> (); stateMachine.Setup(this); animationEvents = transform.parent.GetComponent <AnimationEvents> (); animationEvents.Setup(this); agent = transform.parent.GetComponent <NavMeshAgent> (); navigation = GetComponent <AINavigation> (); navigation.Setup(showAgent); senses = GetComponent <AISenses> (); senses.Setup(); vision = transform.parent.GetComponentInChildren <AIVision> (); vision.Setup(this, showVisionTargets, showNearVision, showMidVision, showFarVision); combat = GetComponent <AICombat> (); combat.Setup(this); if (isZombie) { //Debug.Log ("zombie perception : " + humanSheet.stats.perception); motor = new ZombieMotor(this, transform.parent.GetComponent <Animator> ()); behaviourTree = new BTZombie(); } else { //Debug.Log ("swat perception : " + humanSheet.stats.perception); motor = new HumanMotor(this, transform.parent.GetComponent <Animator> ()); behaviourTree = new BTSwat(); } behaviourTree.squadDeployment = squadDeployment; behaviourTree.Setup(humanSheet, this); //motor.UpdateAvatarMask (); agent.updatePosition = false; //agent.updateRotation = false; behaviourTree.StartTree(); }
public override float ReturnWeight(GameObject owner) { // Get our target from the owner AIVision vision = owner.GetComponent <AIVision>(); // Make sure we have a target if (vision.target == null) { return(100.0f); } // Find Distance float distance = Vector3.Distance(vision.target.transform.position, owner.transform.position); // Work out if we are too far away or too close. float norm = (distance - closestDistance) / (maxDistance - closestDistance); // Apply this to the curve we setup for the scriptable object to get urgency of distance. float eval = urgency.Evaluate(norm) * 100.0f; return(eval); //return base.ReturnWeight(owner); }
void Start() { vision = GetComponentInChildren <AIVision> (); agent = GetComponent <NavMeshAgent> (); }