private SpiderAIBehaviour spider; // TOREFACTOR - this action must be used for any enemy public override void SetAction(AIAction act) { base.SetAction(act); moveAction = (MoveAIAction)act; string tId = moveAction.targetId; spider = (SpiderAIBehaviour)state.parent; // TOREFACTOR - this action must be used for any enemy if (tId != "player") { state.target = GameObject.Find(tId); } else if(!state.target.activeSelf) { state.target = rsc.enemyMng.SelectTarget(); } switch(moveAction.offsetType) { case AIAction.OffsetType.POSITION_ZERO: direction = new Vector3(0, 0, 0); break; case AIAction.OffsetType.AROUND_WORLD_RELATIVE: direction = new Vector3(0, 0, 1); direction = Quaternion.Euler(0, moveAction.angle, 0) * direction; direction *= moveAction.distance; break; case AIAction.OffsetType.AROUND_ENEMY_RELATIVE: direction = (state.agent.transform.position - state.target.transform.position).normalized; direction = Quaternion.Euler(0, moveAction.angle, 0) * direction; direction *= moveAction.distance; break; } if (moveAction.inertia) state.agent.acceleration = 50; else state.agent.acceleration = 1000; state.agent.speed = moveAction.speed; spider.GetComponent<Animator>().speed = moveAction.speed / 4; state.agent.destination = state.target.transform.position + direction; state.agent.Resume(); elapsedTime = 0f; }
public override void SetAction(AIAction act) { base.SetAction(act); moveAction = (MoveAIAction)act; string tId = moveAction.targetId; if (tId == "leader") { if (blackBoard.groupInfo != null && blackBoard.groupInfo.leader != null) { blackBoard.target = blackBoard.groupInfo.leader.gameObject; } } else if (tId == "device") { blackBoard.deviceController = rsc.enemyMng.bb.GetRandomDevice(); if (blackBoard.deviceController != null) { blackBoard.target = blackBoard.deviceController.GetRandomEndPoint(); } } else if (tId != "player") { blackBoard.target = GameObject.Find(tId); } else if ((blackBoard.target == null) || (!blackBoard.target.activeSelf)) { blackBoard.target = rsc.enemyMng.SelectPlayer(blackBoard.entityGO); } if (blackBoard.target != null) { switch (moveAction.offsetType) { case MoveAIAction.OffsetType.POSITION_ZERO: direction = new Vector3(0, 0, 0); break; case MoveAIAction.OffsetType.AROUND_WORLD_RELATIVE: direction = new Vector3(0, 0, 1); direction = Quaternion.Euler(0, moveAction.angle, 0) * direction; direction *= moveAction.distance; break; case MoveAIAction.OffsetType.AROUND_AGENT_RELATIVE: direction = (blackBoard.agent.transform.position - blackBoard.target.transform.position).normalized; direction = Quaternion.Euler(0, moveAction.angle, 0) * direction; direction *= moveAction.distance; break; case MoveAIAction.OffsetType.AROUND_FORWARD_RELATIVE: direction = blackBoard.target.transform.forward; direction = Quaternion.Euler(0, moveAction.angle, 0) * direction; direction *= moveAction.distance; break; } blackBoard.agent.destination = blackBoard.target.transform.position + direction; } if (moveAction.inertia) { blackBoard.agent.acceleration = 50; } else { blackBoard.agent.acceleration = 1000; } blackBoard.agent.speed = moveAction.speed * rsc.gameInfo.globalEnemySpeedFactor; blackBoard.agent.Resume(); blackBoard.animator.SetFloat("moveSpeed", blackBoard.agent.speed / 4); blackBoard.animator.SetBool("moving", true); elapsedTime = 0f; }