public override void DoAction(GameUnit unit, AI_State state) { if (unit.stateC.SlowUpdate()) { unit.agent.SetDestination(unit.agent.destination); } }
private void CheckForStateName() { bool isdown = Input.GetKeyDown(KeyCode.C); if (isdown == true) { currentState = AI_State.CHASE; //Debug.Log("chasing"); } isdown = Input.GetKeyDown(KeyCode.G); if (isdown == true) { currentState = AI_State.GUARD; //Debug.Log("guarding"); } isdown = Input.GetKeyDown(KeyCode.H); if (isdown == true) { currentState = AI_State.HIDE; //Debug.Log("hiding"); } }
public override void DoAction(GameUnit unit, AI_State state) { if (unit.stateC.SlowUpdate()) { unit.stateC.AcquireTarget(unit.transform.position, unit.preset.aggroRange, unit.preset.faction.aggro); } }
public void ChangeState(AI_State nextState) { currentState.EndStateForBrain(this); previousState = currentState; currentState = nextState; currentState.InitializeStateForBrain(this); }
void Update() { if (selectedTarget != null) { EH = selectedTarget.GetComponent <AI_State>(); selectedTarget.GetComponent <AI_State>().UI.SetActive(true); //EH.UI.transform.localRotation = Quaternion.Slerp(transform.rotation, // Quaternion.LookRotation(Self.transform.position - transform.position), // turnSpeed * Time.deltaTime); targetactive = true; if (EH.GetComponent <AI_State>().curHeatlh <= 0) { selectedTarget.GetComponent <AI_State>().UI.SetActive(false); Destroy(selectedTarget.gameObject); } } if (selectedTarget == null) { targetactive = false; } FollowTarget(); }
private IEnumerator Die() { _CurrentSate = StunState; yield return(new WaitForSeconds(1f)); PhotonNetwork.Destroy(gameObject); }
public void refAIState(string state) { switch (state) { case "Spawn": ai_State = AI_State.Spawn; break; case "Moving": ai_State = AI_State.Moving; break; case "Stun": ai_State = AI_State.Stunned; break; case "Dead": ai_State = AI_State.Dead; break; default: Debug.Log("Broke ai_State"); break; } }
IEnumerator AI_Update() { // List<MapTile> CurrentPath = new List<MapTile>(); // UnitState = DetectState(); //the first detect state // StartCoroutine(MoveGenerator()); //Have it update everytime the unit moves to a new tile yield return(new WaitForSeconds(0.5f)); while (true) { yield return(new WaitForSeconds(RefreshRate)); //prevents it from updating too much // Debug.Log("Its updating"); if (ShouldChangePath(UnitState)) { UnitState = DetectState(); //UnitState = AI_State.Chase; UpdateMovementNow = true; // Debug.Log("Changing state to "); } else { //just let it continue their path to wherever } //So first it is gonna check if it needs to change paths or not // The shoudl chage path should update everytime the AI changes tiles } }
// Use this for initialization void Start() { myTrans = GetComponent <Transform> (); startJump = myTrans.position; myState = AI_State.None; direction = Vector3.one; }
private void SetStates(AI_BehaviorBrain brain, AI_BehaviorBrain[] brainList, AI_State state) { foreach (AI_BehaviorBrain currbrain in brainList) { //Debug.Log(currbrain.gameObject.name+" from:"+ currbrain.currentState.ToString()+" to:"+state.ToString()); AI_State currBrainState = currbrain.currentState; if (currBrainState != state) { bool replace = true; foreach (AI_State curState in noReplacedState) { if (currBrainState == curState) { replace = false; break; } } if (replace) { currbrain.ChangeState(state); //currbrain.currentState = state; } } AI_GoToData goToData = currbrain.GetComponent <AI_GoToData>(); if (goToData != null) { if (goToData.destination != brain.transform.position) { goToData.destination = brain.transform.position; } goToData.stopDist = stopDist; } } }
void Attack(LivingBeing target) { State = AI_State.ATTACK; Target = target; TargetPos = Target.Pos; Animator.SetBool("Agressive", true); }
public override void DoAction(GameUnit unit, AI_State state) { unit.agent.avoidancePriority = castAvoidancePriority; unit.stateC.nextAbility = Time.time + unit.preset.ability[unit.stateC.activeAbility].coolDownDuration; unit.stateC.castLockTime = Time.time + unit.preset.ability[unit.stateC.activeAbility].castLockDuration; unit.preset.ability[unit.stateC.activeAbility].ability.Cast(unit, unit.stateC.currentTarget.transform.position); }
public override void DoAction(GameUnit unit, AI_State state) { unit.agent.avoidancePriority = castAvoidancePriority; unit.stateC.nextAbility = Time.time + unit.preset.ability[unit.stateC.activeAbility].coolDownDuration; unit.stateC.castLockTime = Time.time + unit.preset.ability[unit.stateC.activeAbility].castLockDuration; unit.preset.ability[unit.stateC.activeAbility].ability.Cast(unit, unit.controller.worldTarget); }
void Returning() { agent.destination = patrolPoints[0].transform.position; if (distanceToTarget < 2) { currentState = AI_State.Patrolling; } }
public override void DoAction(GameUnit unit, AI_State state) { if (unit.stateC.currentTarget == null) { return; } unit.stateC.distanceToTarget = unit.stateC.CalculateDistToUnit(unit.stateC.currentTarget); }
// Use this for initialization void Start () { myTrans = GetComponent<Transform> (); startJump = myTrans.position; myState = AI_State.None; direction = Vector3.one; }
public override void DoAction(GameUnit unit, AI_State state) { if (unit.stateC.currentTarget == null) { return; } unit.spriteC.faceDirection(unit.transform.position.x <= unit.stateC.currentTarget.transform.position.x); }
void Follow() { agent.destination = Target.transform.position; if (!playerInSight && followDistance > distanceToPlayer) { currentState = AI_State.Returning; } }
void OnEnable() { b = true; _target = (AI_State)target; if (_target._animator != null) { _runtimeAnimatorController = (_target._animator.runtimeAnimatorController as AnimatorController); } }
public void TransitionToState(AI_State nextState) { if (nextState != m_currentState) { OnExitState(); m_currentState = nextState; OnEnterState(); } }
public override void DoAction(GameUnit unit, AI_State state) { if (unit.stateC.currentTarget == null) { return; } unit.agent.SetDestination(unit.stateC.currentTarget.transform.position); unit.spriteC.faceDirection(unit.spriteC.moveRight); }
public void ChangeState(string actionName) { AI_State changeState = aiStates.Find(x => x.aiAction.actionName == actionName); if (changeState != null) { aiMachine.ChangeState(changeState); } }
public void TransitionToState(AI_State nextState) { if (nextState != remainState) { currentState = nextState; OnExitState(); ResetPath(); } }
public void updateFromState(NPCStateData data) { maxHealth = data.maxHP; currentHealth = data.curHP; targetPosition = data.position; targetRotation = data.rotation; State = (AI_State)data.state; UI_Nameplate.updateFromState(data); }
private bool IsLinked(AI_Behaviour behaviour, AI_State state) { if (behaviour.GetType().Name == state.GetType().Name.Substring(3) || behaviour.LinkedStateName == state.GetType().Name) { return(true); } return(false); }
public override void DoAction(GameUnit unit, AI_State state) { if (unit.stateC.cmdTarget != null) { unit.stateC.currentTarget = unit.stateC.cmdTarget; return; } unit.stateC.currentTarget = null; }
void Start () { m_CharacterController = GetComponent<CharacterController>(); m_Jumping = false; currentState = AI_State.GUARD; bTempUsePlayerPosAsCrystal = true; crystal = new Vector3(-1, -1, -1); }
void Start() { m_CharacterController = GetComponent <CharacterController>(); m_Jumping = false; currentState = AI_State.GUARD; bTempUsePlayerPosAsCrystal = true; crystal = new Vector3(-1, -1, -1); }
void Start() { precision = 12; alive = true; state = AI_State.Stand; StartCoroutine(FSM()); m_Nav = gameObject.GetComponent <NavMeshAgent>(); m_transform = gameObject.GetComponent <Transform>(); }
// If the Crab isn't within reach of the player, but is detected by the aggro_range collider move towards it. Otherwise it is close enough to attack. // Gameobject Player is assigned when the player is in range of the aggro colliders inside the crab's hiearchy FOV_Range and Aggro Radius void Chase() { Current_State = AI_State.Walking; turnDirection = Aggro_Target.transform.position - rigidBody.position; turnDirection.Normalize(); transform.rotation = Quaternion.Slerp(transform.rotation, Quaternion.LookRotation(turnDirection), turnSpeed * Time.deltaTime); transform.position += transform.forward * moveSpeed * Time.deltaTime; }
public override void TransitionToState(AI_State nextAIState) { if (nextAIState != remainInAIState) { currentAIState.ExitState(this); OnExitState(); currentAIState = nextAIState; currentAIState.EnterState(this); } }
void Update() { m_distance = Vector3.Distance(transform.position, m_Nav.destination); if (m_distance < m_Nav.stoppingDistance) { state = AI_State.Stand; isMove = false; } Attack_Check(); }
private void Awake() { currentState = initialState; navMeshAgent = this.transform.GetComponent <NavMeshAgent>(); brain_animator = this.transform.GetComponent <Animator>(); brain_rigidbody = this.transform.GetComponent <Rigidbody>(); if (currentState != null) { currentState.InitializeStateForBrain(this); } }
// Use this for initialization void Start () { //FollowState = new AI_State_Follow(); FollowState.Create(UtilityComponents); //TODO rest of the states AllStates = new AI_State[Enum.GetNames(typeof(AI_GUARD_STATE)).Length]; // new List<AI_State>(Enum.GetNames(typeof(AI_GUARD_STATE)).Length); AllStates[(int)AI_GUARD_STATE.Normal] = NormalPatrol; AllStates[(int)AI_GUARD_STATE.Alerted] = AlertedPatrol; AllStates[(int)AI_GUARD_STATE.Follow] = FollowState; State = AI_GUARD_STATE.Normal; curState = NormalPatrol; }
// Method to change AI state public void ChangeState(aiEngineStates newState) { switch(newState) { case aiEngineStates.Attacking: ProcessState = new AI_State(State_Attacking); break; case aiEngineStates.Wandering: ProcessState = new AI_State(State_Wandering); break; default: ProcessState = new AI_State(State_Nothing); break; } }
void ChangeState() { if(playerDist < ai_attack_range && playerDist > ai_retreat_range) { grubState = AI_State.ATTACK; } else if(playerDist > ai_attack_range && distFromStart < ai_max_movement) { grubState = AI_State.HUNT; } else if(playerDist < ai_retreat_range) { grubState = AI_State.RETREAT; } else { grubState = AI_State.PATROL; } }
void OnAwake() { grubState = AI_State.PATROL; }
void Idle() { Target = null; Path.Clear(); State = AI_State.IDLE; Animator.SetBool("Agressive", false); }
public void MoveTo(LocalPos pos) { State = AI_State.MOVE; TargetPos = pos; }
// Passt die Verhaltensweise der KI je nach Alarmstatus an void UpdateState() { if(!allowToPatrol && !allowToLook && !allowToFollow && !allowToShoot) { npcState = AI_State.idle; } else { if (alert >= breakpointFollow) { if (npcSight.playerInSight) { if (allowToShoot) npcState = AI_State.shooting; } else { if (allowToFollow) npcState = AI_State.following; } } else if (alert >= breakpointLooking) { if (allowToLook) npcState = AI_State.looking; } else { if (patrolWayPoints.Length > 0 && NoNullWaypoints() == true) { if (allowToPatrol) npcState = AI_State.patrolling; } else npcState = AI_State.idle; } } }
void Update () { if(bTempUsePlayerPosAsCrystal) { crystal = Player.Inst.transform.position; } CheckForStateName(); if (currentState == AI_State.GUARD) { Vector2 loc = Random.insideUnitCircle * 5; Vector3 newLocation = new Vector3(crystal.x + loc.x, crystal.y, crystal.z + loc.y); Debug.Log(newLocation); Vector3 playerlocation = Player.Inst.transform.position; Vector3 difference = playerlocation - transform.position; float length = difference.magnitude; Vector3 crystalDifference = crystal - transform.position; float crystalDist = crystalDifference.magnitude; // If the player gets too close, run towards them // But only if we are still close to the crystal (otherwise stay near the crystal instead) if( crystalDist < 8 ) { if(length < 8) { Debug.Log("Player is close to gem! Gonna chase them!"); newLocation = playerlocation; } } else { Debug.Log("Too far from crystal! Heading back!"); } move(newLocation); } else if (currentState == AI_State.CHASE) { move(Target.position); Vector3 playerlocation = Player.Inst.transform.position; Vector3 difference = playerlocation - transform.position; float length = difference.magnitude; if (length < 2) { currentState = AI_State.HIDE; bool searchingforlocation = true; while (searchingforlocation) { int depth = VoxelWorld.Inst.VoxelDepth; int width = VoxelWorld.Inst.VoxelWidth; int choicex = Random.RandomRange(0, depth - 1); int choicey = Random.RandomRange(0, width - 1); IntVec3 startinglocation = new IntVec3(choicex, 0, choicey); Voxel v = VoxelWorld.Inst.GetVoxel(startinglocation); bool blockisvalid = true; while (blockisvalid) { startinglocation.Y += 1; if(VoxelWorld.Inst.IsVoxelWorldIndexValid(startinglocation.X, startinglocation.Y, startinglocation.Z)) { Voxel v2 = VoxelWorld.Inst.GetVoxel(startinglocation); if (v2.TypeDef.Type == VoxelType.Air) { hidelocation = startinglocation; searchingforlocation = false; currentState = AI_State.HIDE; Debug.Log("Found a good place to hide the block! Switching to HIDE"); } } else { blockisvalid = false; } } } } } else if (currentState == AI_State.HIDE) { Vector3 hideworldlocation = new Vector3(hidelocation.X, hidelocation.Y, hidelocation.Z); move(hideworldlocation); Vector3 difference = hideworldlocation - transform.position; float length = difference.magnitude; if (length < 4) { Debug.Log("Object hidden! Going back to guarding!"); currentState = AI_State.GUARD; crystal = hideworldlocation; bTempUsePlayerPosAsCrystal = false; } } m_PreviouslyGrounded = m_CharacterController.isGrounded; }
/// <summary> /// 刷新数据 /// </summary> public void Reload(AI_State state) { editSuccess = false; allEventTree.Nodes.Clear(); registedEventTree.Nodes.Clear(); this.m_state = state; flowChartInteractor = Interactor.GetInteractor().CurrentFlowChartInteractor; // 初始化名称 if (string.IsNullOrEmpty(state.Ename)) { state.Ename = string.Format("State{0}", graphElementID.ToString()); } txtName.Text = state.Name; // 初始化所有事件 foreach (AI_Event ai_event in EventTable.EventItems) { // 取消已注册的事件 if (!state.EventList.Contains(ai_event)) { Node node = new Node(); node.Text = ai_event.ToString(); node.Tag = ai_event; if (int.Parse(ai_event.eventid) < 1000) // 系统事件 { node.Image = imageList1.Images[0]; } else { node.Image = imageList1.Images[2]; } allEventTree.Nodes.Add(node); } } // 初始化自定义事件 List<AI_Event> customEventList = flowChartInteractor.CustomTable["CustomEventList"] as List<AI_Event>; if (customEventList != null) { foreach (AI_Event aiEvent in customEventList) { // 去掉已注册的事件 if (!state.EventList.Contains(aiEvent)) { Node node = new Node(); node.Text = aiEvent.ToString(); node.Tag = aiEvent; node.Image = imageList1.Images[2]; allEventTree.Nodes.Add(node); } } } // 初始化选中的事件 foreach (AI_Event aiEvent in state.EventList) { Node node = new Node(); node.Text = aiEvent.ToString(); node.Tag = aiEvent; if (int.Parse(aiEvent.eventid) < 1000) // 系统事件 { node.Image = imageList1.Images[0]; } else { node.Image = imageList1.Images[2]; } registedEventTree.Nodes.Add(node); } // 切换焦点 txtName.Focus(); }