Profile image

Developing trigger script to generate AI Aircraft when the player enters an area [Unity 2018] SOLVED!!!!

314k mikoyanster  4.9 years ago

Hi everyone, I've been able to play a bit with the Unity editor and I've been researching how to program some useful things for future Map Mods. Soon I will be able to share with all these advances. However, I run into a problem, while developing something that I consider fundamental in the design of maps and adventures for SimplePlanes... It is a script that serves to detect when a player enters a predetermined area and execute a series of predetermined actions. In this case, when the player passes through the delimited area, an enemy plane appears, controlled by the AI of the game. I have been searching and inquiring a lot in the manuals and guides available on the Internet and have found several ways to do it, however, I can not get it to work properly. I am convinced that there is some way, and I am close to solving the problem, but I have not found it yet. In this article I publish the experience in the development of this Script and the problems that I am facing.

Situation / context

I am carrying out the tests on a new map that reproduces the Falklands Islands. The stage has been taken from the actual heightmaps of the area and scaled so that it has approximate dimensions to the real place. The idea is that when the player's plane passes through a certain area, an enemy plane appears controlled by the AI of the game. That area for the trigger was named and tag as greenzone and I've recreated it with a transparent green cube. On the other hand I created an AI Aircraft object, whose label, name and ID is "enemy101" It is a Mig-21 test aircraft that I hope to publish soon.

fig1
Fig1. Essential objects for trigger test

With these two objects prepared, I created 2 codes in CSharp/C#. A code that will act as a trigger for the green cube. The idea is that when the player enters the area of the cube, which we have called "greenzone", the object enemy101 appears in the game. I have called this code "miko3TriggerPlane". The other code "miko4EnemyInactive" should serve so that the object of the game called "enemy101" is inactive until the trigger of the "greenzone" is activated. Actually what we are looking for is that the element "enemy101" is hidden until the event is triggered.

The script

Let's take a look at the code...

miko3TriggerPlane
In this code the variables of the player and the "enemy101" which is the AI Aircraft Spawner of SimplePlanes are declared. Then we try to say that at the beginning of the game the object "enemy101" is inactive. For that we use the "SetActive (false)" function. Next, we use the "OnTriggerEnter" function to determine that when the player enters the cube area the action we want is triggered, which is to activate the "enemy101". For that we use the "SetActive (true)" function again. To indicate that the user enters the collision space of the "greenzone", it indicates "Collider other" and the condition "other.tag == Player". However, I have seen this part expressed in several ways, for example ... (Collider player)


using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class miko3TriggerPlane : MonoBehaviour {

public GameObject player;
public GameObject enemy101;

void Start() {
    enemy101.SetActive(false);
}

void OnTriggerEnter(Collider other) {
    if (other.tag == "Player") {
        enemy101.SetActive(true);
    }
}

}
fig2
fig2. miko3TriggerPlane.cs


miko4EnemyInactive
In the tests that I have done, the enemy101 kept appearing even though in the code "miko3TriggerPlane.cs" I have expressly indicated that it is inactive. So I thought about adding this code "miko4EnemyInactive" to try to get it, however the attempts did not work.


using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class miko4EnemyInactive : MonoBehaviour{
public GameObject enemy101;
void Start(){
enemy101.SetActive(false);
}
}
fig3
fig3. miko4EnemyInactive.cs


The problem

I'm pretty sure that the "void OnTriggerEnter ()" function has to be used in this case. However, I do not know what the player's tag or identifier is in SimplePlanes. Maybe it's "player". On the other hand, I do not know how to make the enemy101 only appear when the player passes through the "greenzone". Surely there are many things that are escaping me. If someone can help me or know the solution, I would appreciate it if you could help me with this problem. Thank you very much in advance.

UPDATE 1

Ladies and gentlemen ... I just found the solution, the last test I did worked correctly. I publish in a new post the solution !!!


UPDATE 2

I have achieved it but I have touched something and now it does not work, However, I am reproducing the experiment again and as soon as I have it again, I publish it for everyone.


UPDATE 3

The last tests have been successful, I start writing the procedure to do it ...


  • Log in to leave a comment
  • Profile image

    I think you'll be interested to know that bots and chatbots have been around for decades, but with recent advances in artificial intelligence, the benefits of AI chatbots have become more apparent to businesses and customers alike. I also suggest checking out the Oxagile website, where I learned about their services for developing chatbots for personal interaction without humans.

    4 months ago
  • Profile image
    8,063 Ryn176

    @Kimcotupan15 I already did

    +1 4.9 years ago
  • Profile image

    @Ryn176 use structural wings and XML mod it to have a control surfaces

    4.9 years ago
  • Profile image

    @JohnnyBoythePilot yes this is the idea, i making a map mod as example for all community

    +1 4.9 years ago
  • Profile image

    If this works out fine you should make more combat theater-based maps like Vietnam or the Middle East.

    4.9 years ago
  • Profile image
    8,063 Ryn176

    I need an unrelated help
    My plane kept wobbling whenever I reached 1400 MPH
    So, can anyone help?
    please

    4.9 years ago
  • Profile image
    10.9k Rub3n213

    Not too long till we have player made campaigns!!

    4.9 years ago
  • Profile image
    6,939 Falconhawk

    Trigger was the closest

    4.9 years ago
  • Profile image
    Dev WNP78

    You're welcome!

    +1 4.9 years ago
  • Profile image

    @FairFireFight i will check your problem...

    +1 4.9 years ago
  • Profile image

    Y'all here scripting 'n' sh!t mean while i'm stuck with This error :'(

    4.9 years ago
  • Profile image

    @JamesBleriot Roger that!

    4.9 years ago
  • Profile image
    4,360 JamesBleriot

    @mikoyanster Share it with @AndrewGarrison

    +1 4.9 years ago
  • Profile image

    Can you put a spawn box over skypark navy fleet and by DerekSp and uss beast and then put the whole project in a zipfile for me? Pleeeaaazzz

    +1 4.9 years ago
  • Profile image
    1,323 SovietBias

    Good for Pretty much dogfights or a SimplePlanes film, Great!

    4.9 years ago
  • Profile image

    @MisterT i will share with all community ;-)

    4.9 years ago
  • Profile image
    92.6k MisterT

    Awsome !

    +1 4.9 years ago
  • Profile image

    @MOPCKOEDNISHE @Aerofy

    4.9 years ago
  • Profile image

    @MisterT @DuckMint @Chancey21

    +1 4.9 years ago
  • Profile image

    @Lahoski107 Thank you!

    4.9 years ago