public override void Act(BaseAIController controller) { if (controller.col) { controller.col.enabled = false; } }
void InitAI() { // cache a reference to the AI controller AIController = myGO.GetComponent <BaseAIController>(); // check to see if we found an ai controller component, if not we add one here if (AIController == null) { AIController = myGO.AddComponent <BaseAIController>(); } // initalize the AI controller AIController.Init(); // tell the AI controller to go into waypoint steering mode AIController.SetAIState(AIStates.AIState.steer_to_waypoint); // disable our default input method default_input.enabled = false; // add an AI weapon controller gunControl = myGO.GetComponent <BaseArmedEnemy>(); // if we don't already have a gun controller, let's add one to stop things breaking but // warn about it so that it may be fixed if (gunControl == null) { gunControl = myGO.AddComponent <BaseArmedEnemy>(); Debug.LogWarning("WARNING! Trying to initialize car without a BaseArmedEnemy component attached. Player cannot fire!"); } // tell gun controller to do 'look and destroy' gunControl.currentState = AIAttackStates.AIAttackState.look_and_destroy; }
// main logic public override void Init() { base.Init(); // init player and data managers if (myPlayerManager_New == null) { myPlayerManager_New = (PlayerManager_Tank)myPlayerManager; if (myPlayerManager_New) { myDataManager_New = (UserManager_Tank)myDataManager; } } myDataManager_New.SetDetaleHealth(thisEnemyDetaleStrange); myDataManager_New.SetProtection(thisEnemyProtection); // lets find our ai controller BaseAIController aControl = (BaseAIController)gameObject.GetComponent <BaseAIController> (); // and tell it to chase our player around the screen (we get the player transform from game controller) aControl.SetChaseTarget(GameController_Tank.Instance.GetMainPlayerTransform()); // now get on and chase it! aControl.SetAIState(AIStates.AIState.chasing_target); // we also need to add this enemy to the radar, so we will tell game controller about it and // some code in game controller will do this for us GameController_Tank.Instance.AddEnemyToRadar(myTransform); }
private void DoActions(BaseAIController controller) { for (int i = 0; i < actions.Length; i++) { actions[i].Act(controller); } }
private void Update() { if (BBEG) { BaseAIController ai = BBEG.GetComponent <BaseAIController>(); if (ai.state == caughtState) { if (!playerTookDamage) { player.TakeDamage(2); player.isInvulnerable = true; player.inControl = false; playerTookDamage = true; player.GetStunned(); } } else if (ai.state == leaveAfterCaughtState) { if (!playerHasControl) { player.inControl = true; playerHasControl = true; } } } }
public virtual void Init() { // cache our transform myTransform = transform; // cache our gameObject myGO = gameObject; // cache a reference to the AI controller AIController = myGO.GetComponent <BaseAIController>(); if (AIController == null) { AIController = myGO.AddComponent <BaseAIController>(); } // run the Init function from our base class (BaseAIController.cs) AIController.Init(); // tell AI controller that we want it to control this object AIController.SetAIControl(true); // tell our AI to follow waypoints AIController.SetAIState(AIStates.AIState.translate_along_waypoint_path); // set a flag to tell us that init has happened didInit = true; }
public override bool Decide(BaseAIController controller) { Vector2 playerPosition = ElegarPuzzleQuestManager.Instance.PlayerTransform().position; Vector2 targetDir = playerPosition - (Vector2)controller.eyesPos.position; float angle = Vector2.Angle(targetDir, controller.CharacterDirection()); float distance = Vector2.Distance(playerPosition, controller.eyesPos.position); //if the target if (distance < controller.sightRange && angle < 45f) { int layerMask = 1 << LayerMask.NameToLayer("Bushes"); RaycastHit2D hit = Physics2D.Raycast(controller.eyesPos.position, targetDir.normalized, distance, layerMask); if (hit.collider == null) { return(true); } else { return(false); } } else { return(false); } }
public override void Act(BaseAIController controller) { if (controller.aiWaypoint != null) { controller.ToggleFreezeMovement(false); controller.target = controller.aiWaypoint.transform.position; } }
public override void OnInspectorGUI() { _target = target as BaseAIController; EditorGUILayout.Space(); ShowAIParams(); base.OnInspectorGUI(); }
public override bool Decide(BaseAIController controller) { if (controller.stateTime > controller.state.TimeLimit) { return(true); } else { return(false); } }
public override bool Decide(BaseAIController controller) { if (controller.aiWaypoint.nextWaypont == null) { return(true); } else { return(false); } }
public virtual void Awake() { if (BaseInstance != null && this != BaseInstance) { //There is already a copy of this script running Destroy(this); return; } BaseInstance = this; }
public override bool Decide(BaseAIController controller) { int random; do { random = Random.Range(0, waypoints.Length); }while(Vector2.Distance(controller.transform.position, waypoints[random]) < controller.nextWaypointDistance); controller.target = waypoints[random]; return(true); }
public override void Act(BaseAIController controller) { if (Vector2.Distance((Vector2)(controller.aiWaypoint.transform.position), (Vector2)(controller.transform.position)) < controller.nextWaypointDistance) { controller.aiWaypoint = controller.aiWaypoint.nextWaypont; } if (controller.aiWaypoint != null) { controller.target = controller.aiWaypoint.transform.position; } }
protected override void EnterNotPassedLevel() { if (BBEG) { BBEG.SetActive(true); BaseAIController ai = BBEG.GetComponent <BaseAIController>(); ai.ChangeAIState(introductionState); ai.aiWaypoint = firstWaypoint; } base.EnterNotPassedLevel(); }
public override bool Decide(BaseAIController controller) { int random; do { random = Random.Range(0, targetsToChooseFrom.Length); } while (random == index); index = random; controller.target = targetsToChooseFrom[index]; return(true); }
public override bool Decide(BaseAIController controller) { if (Vector2.Distance((Vector2)(controller.aiWaypoint.transform.position), (Vector2)(controller.transform.position)) < controller.nextWaypointDistance) { if (controller.aiWaypoint.nextWaypont != null) { controller.aiWaypoint = controller.aiWaypoint.nextWaypont; return(true); } } return(false); }
public override bool Decide(BaseAIController controller) { float distance = Vector2.Distance(controller.transform.position, controller.target); if (distance < controller.nextWaypointDistance) { return(true); } else { return(false); } }
public override bool Decide(BaseAIController controller) { Vector2 playerPosition = ElegarPuzzleQuestManager.Instance.PlayerTransform().position; float distance = Vector2.Distance(playerPosition, controller.transform.position); if (distance < controller.hearRange) { return(true); } else { return(false); } }
/// <summary> /// Initialize a state. Call once. /// </summary> /// <param name="enemyProperty"></param> public virtual void Initialize(EnemyProperty enemyProperty) { if (enemyProperty == null) { Debug.LogError("Enemy Property for AI is null!\n"); } _AIController = enemyProperty.GetComponent <BaseAIController> (); if (_AIController == null) { Debug.LogError("Enemy AI Controller is null!\n"); } _stateEnd = false; }
// main logic public override void Init() { base.Init(); // if it hasn't been set in the editor, let's try and find it on this transform if (!AIController) { AIController = myTransform.GetComponent <BaseAIController> (); } // set center of gravity if (!myBody) { myBody.centerOfMass = centerOfGravity; } }
void Start() { // first, let's try to get the AI control script automatically AIControlComponent = GetComponent <BaseAIController>(); myGO = gameObject; myTransform = transform; // quick null check, to warn us if something goes wrong if (AIControlComponent == null) { Debug.LogWarning("SetAIChaseTargetBasedOnTag cannot find BaseAIController"); } InvokeRepeating("LookForChaseTarget", 1.5f, 1.5f); }
void Start() { // cache a ref to our transform myTransform = transform; // if it hasn't been set in the editor, let's try and find it on this transform if (AIController == null) { AIController = myTransform.GetComponent <BaseAIController>(); } // set center of gravity if (myBody != null) { myBody.centerOfMass = centerOfGravity; } }
public override bool Decide(BaseAIController controller) { Vector2 playerPosition = TestManager.Instance.PlayerTransform().position; Vector2 targetDir = playerPosition - (Vector2)controller.transform.position; float angle = Vector3.Angle(targetDir, controller.CharacterDirection()); float distance = Vector2.Distance(playerPosition, controller.transform.position); //if the target if (distance < controller.sightRange && angle < 45f) { return(true); } else { return(false); } }
// here we add respawning and collision to the base armed enemy script public void Start() { base.Start(); // lets find our ai controller BaseAIController aControl = (BaseAIController)gameObject.GetComponent <BaseAIController>(); // and tell it to chase our player around the screen (we get the player transform from game controller) aControl.SetChaseTarget(GameController_LBS.Instance.GetMainPlayerTransform()); // now get on and chase it! aControl.SetAIState(AIStates.AIState.chasing_target); // we also need to add this enemy to the radar, so we will tell game controller about it and // some code in game controller will do this for us GameController_LBS.Instance.AddEnemyToRadar(myTransform); }
private void CheckTransitions(BaseAIController controller) { for (int i = 0; i < transitions.Length; i++) { bool decisionSucceeded = transitions[i].decision.Decide(controller); if (decisionSucceeded) { if (controller.state != transitions[i].trueState) { controller.ChangeAIState(transitions[i].trueState); return; } } else { if (controller.state != transitions[i].falseState) { controller.ChangeAIState(transitions[i].falseState); return; } } } }
public override void Act(BaseAIController controller) { controller.target = controller.transform.position; }
void Init() { // incase we need to change the timescale, it gets set here Time.timeScale = gameSpeed; // tell race manager to prepare for the race GlobalRaceManager.Instance.InitNewRace(totalLaps); // initialize some temporary arrays we can use to set up the players Vector3 [] playerStarts = new Vector3 [numberOfRacers]; Quaternion [] playerRotations = new Quaternion [numberOfRacers]; // we are going to use the array full of start positions that must be set in the editor, which means we always need to // make sure that there are enough start positions for the number of players for (int i = 0; i < numberOfRacers; i++) { // grab position and rotation values from start position transforms set in the inspector playerStarts [i] = (Vector3)startPoints [i].position; playerRotations [i] = ( Quaternion )startPoints [i].rotation; } SpawnController.Instance.SetUpPlayers(playerPrefabList, playerStarts, playerRotations, playerParent, numberOfRacers); playerTransforms = new ArrayList(); // now let's grab references to each player's controller script playerTransforms = SpawnController.Instance.GetAllSpawnedPlayers(); playerList = new ArrayList(); for (int i = 0; i < numberOfRacers; i++) { Transform tempT = (Transform)playerTransforms[i]; CarController_MVD tempController = tempT.GetComponent <CarController_MVD>(); playerList.Add(tempController); BaseAIController tempAI = tempController.GetComponent <BaseAIController>(); // tell each player where to find the waypoints tempAI.SetWayController(WaypointControllerForAI); tempController.Init(); // tell the car controller script about the waypoint controller so it can pass it on to the racecontroller (!) tempController.SetWayController(WaypointControllerForAI); } // grab a ref to the player's gameobject for later playerGO1 = SpawnController.Instance.GetPlayerGO(0); // add an audio listener to the first car so that the audio is based from the car rather than the main camera playerGO1.AddComponent <AudioListener>(); // look at the main camera and see if it has an audio listener attached AudioListener tempListener = Camera.main.GetComponent <AudioListener>(); // if we found a listener, let's destroy it if (tempListener != null) { Destroy(tempListener); } // grab a reference to the focussed player's car controller script, so that we can // do things like access its speed variable focusPlayerScript = ( CarController_MVD )playerGO1.GetComponent <CarController_MVD>(); // assign this player the id of 0 focusPlayerScript.SetID(0); // set player control focusPlayerScript.SetUserInput(true); // tell the camera script to target this new player cameraScript.SetTarget(playerGO1.transform); // do initial lap counter display UpdateLapCounter(1); // lock all the players on the spot until we're ready to go SetPlayerLocks(true); // start the game in 3 seconds from now Invoke("StartRace", 4); // update positions throughout the race, but we don't need // to do this every frame, so just do it every half a second instead InvokeRepeating("UpdatePositions", 0.5f, 0.5f); // hide our count in numbers HideCount(); // schedule count in messages Invoke("ShowCount3", 1); Invoke("ShowCount2", 2); Invoke("ShowCount1", 3); Invoke("HideCount", 4); // hide final position text finalPositionText.gameObject.SetActive(false); doneFinalMessage = false; // start by hiding our wrong way message wrongWaySign.SetActive(false); didInit = true; }
public abstract void Act(BaseAIController controller);
public override void Act(BaseAIController controller) { controller.ToggleFreezeMovement(false); controller.speed = newSpeed; }