public virtual void Init () { m_Steering = new AiSteering(); m_Character = this.gameObject; m_Agent = gameObject.GetComponent<AiAgent>(); if (m_Agent == null) Debug.LogError("No AiAgent component found"); }
public virtual void Instantiate() { if (this.energyCost > system.master.mana) { return; } if (system.ownerType == SkillSystem.SkillOwnerType.AI) { AiAgent ag = system.master as AiAgent; Magic go = (Magic)MonoBehaviour.Instantiate(this.magicBall, startPoint.position, startPoint.rotation); go.target = ag.target.transform; go.skill = this; this.cooling = true; } if (system.ownerType == SkillSystem.SkillOwnerType.Player) { Magic go = (Magic)MonoBehaviour.Instantiate(this.magicBall, startPoint.position, startPoint.rotation); go.skill = this; go.startPoint = startPoint; this.cooling = true; } this.system.master.mana -= this.energyCost; if (this.system.master.mana < 0) { this.system.master.mana = 0; } }
public void Update(AiAgent agent) { // Vector3 playerDirection = agent.playerTransform.position - agent.transform.position; // if (playerDirection.magnitude > agent.config.viewDistance) // { // return; // } // // Vector3 agentDirection = agent.transform.forward; // // playerDirection.Normalize(); // // float dotProduct = Vector3.Dot(playerDirection, agentDirection); // // if (dotProduct > 0.0) // { // agent.stateMachine.ChangeState(AiStateId.ChasePlayer); // } if (agent.weapons.hasWeapon && Vector3.Distance(agent.transform.position, agent.playerTransform.position) < agent.config.viewDistance) { agent.stateMachine.ChangeState(AiStateId.AttackPlayer); } }
public override void OnStateEnter(Animator animator, AnimatorStateInfo stateInfo, int layerIndex) { base.OnStateEnter(animator, stateInfo, layerIndex); _remainingFlightDuration = _flightDuration; _aiAgent = animator.GetComponent <AiAgent>(); SetFleeDestination(); }
public AiStateMachine(AiAgent agent) { this.agent = agent; int numStates = System.Enum.GetNames(typeof(AiStateId)).Length; states = new AiState[numStates]; }
public void Update(AiAgent agent) { if (agent.weapons.HasWeapon() && Vector3.Distance(agent.transform.position, agent.playerTransform.position) < agent.config.viewDistance) { agent.stateMachine.ChangeState(AiStateId.AttackPlayer); } }
// Use this for initialization void Start() { winner.gameObject.SetActive(false); loser.gameObject.SetActive(false); enemies = GameObject.FindGameObjectsWithTag("Enemy"); items = GameObject.FindGameObjectsWithTag("Pickable"); Ai1 = AiAgentPrefab.GetComponent <AiAgent>(); P1 = PlayerAgentPrefab.GetComponent <Player>(); SP1 = GameObject.Find("SP1"); SP2 = GameObject.Find("SP2"); SP3 = GameObject.Find("SP3"); SP4 = GameObject.Find("SP4"); SP5 = GameObject.Find("SP5"); SP6 = GameObject.Find("SP6"); SP7 = GameObject.Find("SP7"); SP8 = GameObject.Find("SP8"); SP9 = GameObject.Find("SP9"); SP10 = GameObject.Find("SP10"); disableSpawnPoint(); // For testing spawn points are visable, they are invisable in runtime InvokeRepeating("delayedRandomNumberGenerator", 0, 5f); // new number every 2 seconds spawnAtRandom(); }
public void Update(AiAgent agent) { float sqrDistancePfromA = (agent.playerTransform.position - agent.weapons.currentWeapon.shootingPoint.position).sqrMagnitude; float sqrShootingRange = agent.weapons.currentWeapon.shootingRange * agent.weapons.currentWeapon.shootingRange; //Debug.Log("distance : " +sqrDistancePfromA + "\n range :" + sqrShootingRange); PlayerInSightCheck(sqrDistancePfromA, sqrShootingRange, agent); agent.transform.LookAt(agent.playerTransform.position, Vector3.up); if (Time.time > agent.weapons.currentWeapon.nextRandom) { agent.weapons.SetTarget(agent.playerTransform); agent.weapons.currentWeapon.nextRandom = Time.time + agent.weapons.currentWeapon.randomSpeed; } if (sqrDistancePfromA > sqrShootingRange) { agent.navMeshAgent.destination = agent.playerTransform.position; } if (!agent.weapons.weaponActive && sqrDistancePfromA < sqrShootingRange) { return; } // implement going around sphere if shooting }
public void Enter(AiAgent agent) { agent.ragdoll.ActivateRagdoll(); Direction.y = 0.5f; agent.ragdoll.ApplyForce(Direction * ForceFromWep); agent.healthBar.gameObject.SetActive(false); agent.weapons.DropWeaon(); agent.weapons.enabled = false; agent.navMeshAgent.enabled = false; }
public virtual void Init() { m_Steering = new AiSteering(); m_Character = this.gameObject; m_Agent = gameObject.GetComponent <AiAgent>(); if (m_Agent == null) { Debug.LogError("No AiAgent component found"); } }
public void ResetPath() { if (lineRenderer != null) { lineRenderer.positionCount = 0; } if (currentAgent != null) { currentAgent.OnDeath -= ResetPath; } currentAgent = null; }
public void ShowPath(List <Vector3> path, AiAgent agent, Color color) { ResetPath(); lineRenderer.positionCount = path.Count; lineRenderer.startColor = color; lineRenderer.endColor = color; for (int i = 0; i < path.Count; i++) { lineRenderer.SetPosition(i, path[i] + new Vector3(0, agent.transform.position.y, 0)); } currentAgent = agent; currentAgent.OnDeath += ResetPath; }
public override void OnStateEnter(Animator animator, AnimatorStateInfo stateInfo, int layerIndex) { base.OnStateEnter(animator, stateInfo, layerIndex); _aiAgent = animator.GetComponent <AiAgent>(); if (_aiAgent.HiringPlayer == null) { SetIsNotHired(animator); return; } _remainingHireDuration = _hireDuration; _followTarget = _aiAgent.HiringPlayer.transform; }
public void Enter(AiAgent agent) { if (agent.weapons.hasWeapon) { agent.stateMachine.ChangeState(AiStateId.Idle); } if (!agent.weapons.hasWeapon) { WeaponPickup pickup = FindClosetWeapon(agent); agent.navMeshAgent.destination = pickup.transform.position; agent.navMeshAgent.speed = 5; } }
public void ChooseASkill() { if (ownerType == SkillOwnerType.AI) { AiAgent ag = this.master as AiAgent; //从已冷却的技能列表中随机取出一个技能释放 //List<Skill> _tSkill = this.CooledList ; List <Skill> _tSkill = this.EnabledList; if (_tSkill.Count <= 0) { return; } int i = Random.Range(0, _tSkill.Count); skillToRelease = _tSkill[i]; skillToRelease.startPoint = ag.shootPoint; ag.animController.Play_Shot(); } }
private WeaponPickup FindClosetWeapon(AiAgent agent) { WeaponPickup[] weapons = Object.FindObjectsOfType <WeaponPickup>(); WeaponPickup closestWeapon = null; float closestDistance = float.MaxValue; foreach (var weapon in weapons) { float distanceToWeapon = Vector3.Distance(agent.transform.position, weapon.transform.position); if (distanceToWeapon < closestDistance) { closestDistance = distanceToWeapon; closestWeapon = weapon; } } return(closestWeapon); }
void PlayerInSightCheck(float sqrDistancePfromA, float sqrShootingRange, AiAgent agent) { bool playerInSight = RaycastCheckIsPlayerInSight(agent, sqrDistancePfromA, sqrShootingRange); if (playerInSight) { _delayInterval += Time.deltaTime; if (!agent.weapons.weaponActive && _delayInterval > agent.weapons.DelayTillAttacking) { agent.weapons.weaponActive = true; } } if (!playerInSight) { agent.weapons.weaponActive = false; _delayInterval = 0; } }
/// <summary> /// This runs once for each Fuego player in a game, but only for players, not the assistant. It determines whether /// this <see cref="Fuego"/> instance is /// </summary> /// <param name="aiAgent">The ai agent.</param> public void Initialize(AiAgent aiAgent) { var gameState = aiAgent.GameState; // Determine primary player foreach (var player in gameState.Players) { // ReSharper disable once UseNullPropagation - for clarity if (player.Agent is AiAgent) { AiAgent thatAgent = player.Agent as AiAgent; if (thatAgent.AI is Fuego) { // ReSharper disable once ConvertIfStatementToConditionalTernaryExpression - for clarity if (thatAgent == aiAgent) { _isPrimaryPlayer = true; } else { _isPrimaryPlayer = false; } break; } } } // If you're the primary player, establish the game. if (_isPrimaryPlayer) { if (FuegoSingleton.Instance.CurrentGame != null && FuegoSingleton.Instance.CurrentGame.Players.All(pl => pl.Agent != aiAgent)) { // A game is in progress and it doesn't include this AI. _brokenDueToInvalidLaunch = true; } } }
public void Update(AiAgent agent) { float sqrDistance = (agent.playerTransform.position - agent.navMeshAgent.destination).sqrMagnitude; if (sqrDistance < agent.weapons.currentWeapon.shootingRange * agent.weapons.currentWeapon.shootingRange) { agent.stateMachine.ChangeState(AiStateId.AttackPlayer); } if (!agent.navMeshAgent.hasPath) { agent.navMeshAgent.destination = agent.playerTransform.position; } _timer -= Time.deltaTime; if (_timer < 0.0f) { if (sqrDistance > agent.config.maxDistance * agent.config.maxDistance) { agent.navMeshAgent.destination = agent.playerTransform.position; } _timer = agent.config.maxTime; } }
bool RaycastCheckIsPlayerInSight(AiAgent agent, float sqrDistancePfromA, float sqrShootingRange) { if (agent.weapons.currentWeapon.weaponType == RaycastWeapon.WeaponType.MeleeWeapon) { return(true); } Ray ray = new Ray(agent.weapons.currentWeapon.shootingPoint.position, agent.weapons.currentWeapon.shootingPoint.forward); if (agent.weapons.showWeaponRange) { Debug.DrawRay(ray.origin, ray.direction * agent.weapons.currentWeapon.shootingRange, Color.magenta); } if (Physics.Raycast(ray, out RaycastHit hit, agent.weapons.currentWeapon.shootingRange)) { if (hit.collider.GetComponent <PlayerController>() || hit.transform.gameObject.layer == layerProp) { return(true); } if (!hit.collider.GetComponent <PlayerController>()) { return(false); } } if (sqrDistancePfromA < sqrShootingRange) { return(true); } if (sqrDistancePfromA > sqrShootingRange) { return(false); } return(false); }
// Update is called once per frame void Update() { if (!playerWeapon.weapon.isFiring) { return; } Collider[] hits = (Physics.OverlapBox(transform.position, new Vector3(boxSize, 1.5f, boxSize), transform.rotation)); foreach (var hit in hits) { AiAgent agent = hit.GetComponent <AiAgent>(); AiInnocent inno = hit.GetComponent <AiInnocent>(); if (agent && agent.stateMachine.currentState != AiStateId.AttackPlayer) { agent.stateMachine.ChangeState(AiStateId.AttackPlayer); } if (inno && inno.stateMachine.currentState != InnocentStateId.Run) { inno.stateMachine.ChangeState(InnocentStateId.Run); } } }
public override void Apply(AiAgent agent) { DestroyPointObj(agent.WorldId, m_nodeId); }
public override void OnStateEnter(Animator animator, AnimatorStateInfo stateInfo, int layerIndex) { _aiAgent = animator.GetComponent <AiAgent>(); UpdateRoamPosition(); }
// Use this for initialization void Start () { m_Agent = GetComponent<AiAgent>(); }
public override void OnStart() { agent = GetComponent <AiAgent>(); }
public void Enter(AiAgent agent) { }
public override void Apply(AiAgent agent) { CreatePointObj(agent.WorldId, m_nodeId, m_worth, m_type); }
public void Exit(AiAgent agent) { // agent.navMeshAgent.stoppingDistance = 0.0f; }
// Use this for initialization void Start() { maingame = Gm.GetComponent <GameScript>(); Ai1 = AiPrefab.GetComponent <AiAgent>(); }
public override void OnStateEnter(Animator animator, AnimatorStateInfo stateInfo, int layerIndex) { base.OnStateEnter(animator, stateInfo, layerIndex); _remainingPrice = _hirePrice; _aiAgent = animator.GetComponent <AiAgent>(); }
public void Update(AiAgent agent) { }
public void Exit(AiAgent agent) { }
public abstract void Apply(AiAgent agent);
// Use this for initialization void Start() { m_Agent = GetComponent <AiAgent>(); }
public override void Apply(AiAgent agent) { CreateConnection(agent.WorldId, m_from, m_to, m_direction, m_cost); }
public override void Apply(AiAgent agent) { CreateNode(agent.WorldId, m_node.NodeId, m_position); }
public void Enter(AiAgent agent) { agent.weapons.SetWeightAiming(1); agent.weapons.DrawWeapon(true); layerProp = LayerMask.NameToLayer("Prop"); }