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
[18668-nervus+running.png|18668]
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 : )/