Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
This post has been wikified, any user with enough reputation can edit it.
avatar image
0
Question by Enyrgis · Nov 28, 2013 at 01:04 PM · variablefunctioncallpass

Building a 3D Neural Network for Bot AI?

So the Idea

This is supposed to be a neural network in 3d cubes drag and drop at some point...

1...The cube sends out a Pulse (name,name,name,number) call function to each other cube / clone .

2...Each cube checks if the Pulse caries its name.

3...If it true it edits the number and adds the next 3 names.

4... Finally it sends a Pulse to the next script and function as a Pulse(name,name,name,number).

1-4..... this repeats until the pulse hits an output block or fails to pass all thresholds on the way.

Working On / Questions

A?...At the moment its a structure, and only transmits if you build and link each block by hand,
so how to make it link like a chain while instantiating to avoid the by hand part?

B?... How to do drag and drop cubes?

C?... what is wrong with the set parent functions i can not get the links to stay stable....note there is an edited set if instantiate calls that have a glitch in the nerveController script?

E?... what should i change the name of this question to...?

Notes And thank you Phil Rousse, for the awesome first response it is appreciated

Link to package: 77.81 kbs: 4 scripts, 2 folders, 3 pngs, 4 prefabs...very simple is the goal https://www.dropbox.com/s/jykmhw9prj42lh7/Neural%20Cubes.unitypackage

alt text

Nerve Controller

 public class nerveController : MonoBehaviour 
 {
     // Nerve cells use to send/recive Pulses
     public inputCell linkInputCell;
     public nerveCell linkNerveCell;
     public outputCell linkOutputCell;
 
     public Transform NerveController;
     public Transform inputCell;
     public Transform nerveCell;
     public Transform outputCell;
 
     public Vector3 grid=new Vector3(9.0f,9.0f,9.0f);
     Vector3 location=new Vector3(0.0f,0.0f,0.0f);
      
     void Awake(){
 
         location= transform.position;
         Instantiate (inputCell, new Vector3 (location.x+1, location.y+0, location.z+1), Quaternion.identity);
         Instantiate (outputCell, new Vector3 (location.x+grid.x, location.y+grid.y+1, location.z+grid.z), Quaternion.identity);
 
         for(int x=1;x<=grid.x;x++){
             for(int y=1;y<=grid.y;y++){
                 for(int z=1;z<=grid.z;z++){
 
                     Instantiate (nerveCell, new Vector3(location.x+x, location.y+y, location.z+z), Quaternion.identity);
 
 
                     //GameObject instance = Instantiate (nerveCell, new Vector3(location.x, location.y, location.z), Quaternion.identity) as GameObject;
 
                     //instance.transform.parent = NerveController;
                 }
             }
         }
         //GameObject instance = Instantiate (outputCell, new Vector3 (location.x+grid.x, location.y+grid.y+1, location.z+grid.z), Quaternion.identity) as GameObject;    
 
         //instance.transform.parent = NerveController;
         
         //GameObject instance = Instantiate (inputCell, new Vector3 (location.x+1, location.y+0, location.z+1), Quaternion.identity) as GameObject;
 
         //instance.transform.parent = NerveController;
 
     }
 }


Nerve Cells

 public class nerveCell : MonoBehaviour
 {
     // Nerve cells use to send/recive Pulses
     public inputCell linkInputCell;
     public nerveCell linkNerveCell;
     public outputCell linkOutputCell;
         
     public float output = 0;
     public float multiplyer;
     public float threshhold;
 
 
     public Vector3 Name = new Vector3 (0f, 0f, 0f);
     Vector3 callNamea = new Vector3 (1f, 0f, 0f);
     Vector3 callNameb = new Vector3 (0f, 1f, 0f);
     Vector3 callNamec = new Vector3 (0f, 0f, 1f);
 
     // awake so choose its settings for multi and thresh
     float awake = 0; 
     void Awake ()
     {
         if (awake == 0) {     
             //update own name
             Name = transform.position;
             multiplyer = Random.Range (-1.5f, 2.5f);
             threshhold = Random.Range (-1.5f, 2.5f);
             awake++;
         }
     }
 
     public void Pulse (float pulseIntensity, Vector3 callNamex, Vector3 callNamey, Vector3 callNamez)
     {
         //
         if (pulseIntensity * multiplyer >= threshhold) {
 
             //update own name
             Name = transform.position;
 
             //check if Pulse is ment for self or else ignore
             if (Name == callNamex || Name == callNamey || Name == callNamez) {
 
             //Update the Pulseintensity before sending
             pulseIntensity = pulseIntensity * multiplyer;
             output = pulseIntensity;
 
             //update the call names before sending
             callNamex = callNamea + Name;
             callNamey = callNameb + Name;
             callNamez = callNamec + Name;
 
             // now send updated pulse to next nerves called by location
             linkNerveCell.Pulse (pulseIntensity, callNamex, callNamey, callNamez);
             linkOutputCell.Pulse (pulseIntensity, callNamex, callNamey, callNamez);
 
             }
         }
     }

}

Input Cell

 public class inputCell : MonoBehaviour
 {
     // Nerve cells use to send/recive Pulses
     public inputCell linkInputCell;
     public nerveCell linkNerveCell;
     public outputCell linkOutputCell;
 
     //this is visibal while in play so to adjust the settint
     public float inputIntensity = 3;
     public float output = 0; 
 
     //These store the cells own name and the names of those it talks to....vector phone numbers
     public Vector3 Name = new Vector3 (0f, 0f, 0f);
     Vector3 callNamea = new Vector3 (1f, 0f, 0f);
     Vector3 callNameb = new Vector3 (0f, 1f, 0f);
     Vector3 callNamec = new Vector3 (0f, 0f, 1f);
     
     //The Function to fire data in to the network
     void Pulse (float pulseIntensity)
     {
             //let us check if pulse came in...
             output = pulseIntensity;
 
             //update own name
             Name = transform.position;
 
             //make the call names before sending
             Vector3 callNamex = callNamea + Name;
             Vector3    callNamey = callNameb + Name;
             Vector3 callNamez = callNamec + Name;
 
             // now send updated pulse to next nerves called by location
             linkNerveCell.Pulse(pulseIntensity, callNamex, callNamey, callNamez);
             linkOutputCell.Pulse(pulseIntensity, callNamex, callNamey, callNamez);            
     }
     //        NullReferenceException: Object reference not set to an instance of an object inputCell.Pulse (Single pulseIntensity) (at Assets/xyz Nerve System/inputCell.cs:37) inputCell.OnGUI () (at Assets/xyz Nerve System/inputCell.cs:48)
 
 //A TEST button
 
         void OnGUI ()
         {
                 // make a button that fires a pulse out of the input node in to the network
                 if (GUI.Button (new Rect (10, 10, 60, 30), "Pulse")) {
                         Pulse(inputIntensity);
 
 //    SendMessage("Pulse",inputIntensity,callNamex,callNamey,callNamez);
 
 //Pulse(inputIntensity,callNamex,callNamey,callNamez);
 
 //Pulse(0+1);
                 }
 
         }
 
 }


Output Cell

 public class outputCell : MonoBehaviour 
 {
     // Nerve cells use to send/recive Pulses
     public inputCell linkInputCell;
     public nerveCell linkNerveCell;
     public outputCell linkOutputCell;
 
     //make shure  the Cell only wakes up once
     private float awake = 0; 
     public float output=0;
     
     // when created and wake up takes a  name from its position, decides on output targets
     public Vector3 Name = new Vector3(0f,0f,0f);
     Vector3 callNamea = new Vector3(1f,0f,0f);
     Vector3 callNameb = new Vector3(0f,1f,0f);
     Vector3 callNamec = new Vector3(0f,0f,1f);
 
     // then and choose its settings for multi and thresh
     void Awake(){
         if (awake==0){
             Name=transform.position;
             awake++;
         }
     }
     
     public void Pulse(float pulseIntensity, Vector3 callNamex,Vector3 callNamey, Vector3 callNamez){
 
         //update own name
         Name = transform.position;
 
         if(Name==callNamex || Name==callNamey || Name==callNamez){
             output=pulseIntensity;
         }
     }
 
     void OnGUI() {
         GUI.Button(new Rect(80, 10, 50, 50), "#"+output);    
     }
     
     
 }
 

suggestions on the code would be awesome.

This is supposed to resemble a neural network in 3d

thanks for any and all help

feel free to learn, i wrote it to share....lol : )/

nervus running.png (106.9 kB)
Comment
Add comment
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

1 Reply

· Add your reply
  • Sort: 
avatar image
0
Wiki

Answer by PhilRousse · Nov 28, 2013 at 02:42 PM

There multiple way:

  1. You need to keep an handle on the GameObject or Component that you are trying to access. Here some code example

    nerveCell[][][] grid;

    inputCell inCell;

    outputCell outCell;

      [...]
         
         void InitGrid()
         {
             //Initialize the grid
             grid = new nerveCell[gridx][][];
             for(int i = 0; i < gridx; i++)
             {
                 grid[i] = new GridPiece[gridy][];
         
                 for(int j = 0; j < gridy; j++)
                 {
                     grid[i][j] = new GridPiece[gridz];
                 }
             }
         }
         
         void Awake()
         {
         
             InitGrid();
         
             //We instantiate and keep a reference on their Cell script.
             inCell = Instantiate(inputCell, new Vector3 (1, 0, 1), Quaternion.identity).GetComponent<inputCell>();
             outCell = Instantiate (outputCell, new Vector3 (gridx, gridy+1, gridz), Quaternion.identity).GetComponent<outputCell>();
             for(int x=0;x< gridx;x++)
             {
                 for(int y=0;y< gridy;y++)
                 {
                     for(int z=0;z< gridz;z++)
                     {
              
                         //We instantiate and keep a reference on their nerveCell script.
                         grid[x][y][z] = Instantiate (nerveCell, new Vector3 (x+1, y+1, z+1), Quaternion.identity).GetComponent<nerveCell>();
             
                         //That permit to call any of there fonction
                         grid[x][y][z].Pulse(2.0f, new Vector3(0,6,9),new Vector3(0,6,9),new Vector3(0,6,9));
                     }
                 }
             }
    
    
  2. You can send a message. But your grid need to be the children of another gameObject and you can't target a specific gameObject

  3. You can seach for your gameObject, Get there component and call the function. This can be an Heavy function for the CPU.

If you want me to develop option 2 and 3, please comment

Comment
Add comment · Show 2 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image Enyrgis · Nov 28, 2013 at 04:22 PM 0
Share

Thank You Phil! i updated the question and set it to public... and attached a pic and link to my file. for anyone who wants to play...

avatar image Enyrgis · Dec 07, 2013 at 10:09 AM 0
Share

i need to learn more about matrices, i just can't make it fly that way yet....another week maybe

This is the complete project code if you want to look.

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

17 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Calling a Function from other script ( C# ) 1 Answer

How to use different types of scripts with an override function. 2 Answers

How to call Variable across scripts. 2 Answers

Get variable from another object 1 Answer

Why can't I call function from another script? 1 Answer


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges