Using velocity receptor
This commit is contained in:
parent
cb8c9dbb7c
commit
61bdc36e84
@ -374,9 +374,10 @@ MonoBehaviour:
|
|||||||
m_Name:
|
m_Name:
|
||||||
m_EditorClassIdentifier: Assembly-CSharp::SwarmControl
|
m_EditorClassIdentifier: Assembly-CSharp::SwarmControl
|
||||||
speed: 1
|
speed: 1
|
||||||
inertia: 0.8
|
inertia: 0.7
|
||||||
alignmentForce: 9
|
alignmentForce: 0
|
||||||
cohesionForce: 4
|
cohesionForce: 4
|
||||||
|
separationForce: -5
|
||||||
avoidanceForce: 5
|
avoidanceForce: 5
|
||||||
separationDistance: 0.3
|
separationDistance: 0.3
|
||||||
perceptionDistance: 2
|
perceptionDistance: 2
|
||||||
|
|||||||
84
Assets/Scenes/Boids/Materials/Red.mat
Normal file
84
Assets/Scenes/Boids/Materials/Red.mat
Normal file
@ -0,0 +1,84 @@
|
|||||||
|
%YAML 1.1
|
||||||
|
%TAG !u! tag:unity3d.com,2011:
|
||||||
|
--- !u!21 &2100000
|
||||||
|
Material:
|
||||||
|
serializedVersion: 8
|
||||||
|
m_ObjectHideFlags: 0
|
||||||
|
m_CorrespondingSourceObject: {fileID: 0}
|
||||||
|
m_PrefabInstance: {fileID: 0}
|
||||||
|
m_PrefabAsset: {fileID: 0}
|
||||||
|
m_Name: Red
|
||||||
|
m_Shader: {fileID: 46, guid: 0000000000000000f000000000000000, type: 0}
|
||||||
|
m_Parent: {fileID: 0}
|
||||||
|
m_ModifiedSerializedProperties: 0
|
||||||
|
m_ValidKeywords: []
|
||||||
|
m_InvalidKeywords: []
|
||||||
|
m_LightmapFlags: 4
|
||||||
|
m_EnableInstancingVariants: 0
|
||||||
|
m_DoubleSidedGI: 0
|
||||||
|
m_CustomRenderQueue: -1
|
||||||
|
stringTagMap: {}
|
||||||
|
disabledShaderPasses: []
|
||||||
|
m_LockedProperties:
|
||||||
|
m_SavedProperties:
|
||||||
|
serializedVersion: 3
|
||||||
|
m_TexEnvs:
|
||||||
|
- _BumpMap:
|
||||||
|
m_Texture: {fileID: 0}
|
||||||
|
m_Scale: {x: 1, y: 1}
|
||||||
|
m_Offset: {x: 0, y: 0}
|
||||||
|
- _DetailAlbedoMap:
|
||||||
|
m_Texture: {fileID: 0}
|
||||||
|
m_Scale: {x: 1, y: 1}
|
||||||
|
m_Offset: {x: 0, y: 0}
|
||||||
|
- _DetailMask:
|
||||||
|
m_Texture: {fileID: 0}
|
||||||
|
m_Scale: {x: 1, y: 1}
|
||||||
|
m_Offset: {x: 0, y: 0}
|
||||||
|
- _DetailNormalMap:
|
||||||
|
m_Texture: {fileID: 0}
|
||||||
|
m_Scale: {x: 1, y: 1}
|
||||||
|
m_Offset: {x: 0, y: 0}
|
||||||
|
- _EmissionMap:
|
||||||
|
m_Texture: {fileID: 0}
|
||||||
|
m_Scale: {x: 1, y: 1}
|
||||||
|
m_Offset: {x: 0, y: 0}
|
||||||
|
- _MainTex:
|
||||||
|
m_Texture: {fileID: 0}
|
||||||
|
m_Scale: {x: 1, y: 1}
|
||||||
|
m_Offset: {x: 0, y: 0}
|
||||||
|
- _MetallicGlossMap:
|
||||||
|
m_Texture: {fileID: 0}
|
||||||
|
m_Scale: {x: 1, y: 1}
|
||||||
|
m_Offset: {x: 0, y: 0}
|
||||||
|
- _OcclusionMap:
|
||||||
|
m_Texture: {fileID: 0}
|
||||||
|
m_Scale: {x: 1, y: 1}
|
||||||
|
m_Offset: {x: 0, y: 0}
|
||||||
|
- _ParallaxMap:
|
||||||
|
m_Texture: {fileID: 0}
|
||||||
|
m_Scale: {x: 1, y: 1}
|
||||||
|
m_Offset: {x: 0, y: 0}
|
||||||
|
m_Ints: []
|
||||||
|
m_Floats:
|
||||||
|
- _BumpScale: 1
|
||||||
|
- _Cutoff: 0.5
|
||||||
|
- _DetailNormalMapScale: 1
|
||||||
|
- _DstBlend: 0
|
||||||
|
- _GlossMapScale: 1
|
||||||
|
- _Glossiness: 0.5
|
||||||
|
- _GlossyReflections: 1
|
||||||
|
- _Metallic: 0
|
||||||
|
- _Mode: 0
|
||||||
|
- _OcclusionStrength: 1
|
||||||
|
- _Parallax: 0.02
|
||||||
|
- _SmoothnessTextureChannel: 0
|
||||||
|
- _SpecularHighlights: 1
|
||||||
|
- _SrcBlend: 1
|
||||||
|
- _UVSec: 0
|
||||||
|
- _ZWrite: 1
|
||||||
|
m_Colors:
|
||||||
|
- _Color: {r: 1, g: 0, b: 0, a: 1}
|
||||||
|
- _EmissionColor: {r: 0, g: 0, b: 0, a: 1}
|
||||||
|
m_BuildTextureStacks: []
|
||||||
|
m_AllowLocking: 1
|
||||||
8
Assets/Scenes/Boids/Materials/Red.mat.meta
Normal file
8
Assets/Scenes/Boids/Materials/Red.mat.meta
Normal file
@ -0,0 +1,8 @@
|
|||||||
|
fileFormatVersion: 2
|
||||||
|
guid: 2a7557e54580b6a8b976f12aa6cc761c
|
||||||
|
NativeFormatImporter:
|
||||||
|
externalObjects: {}
|
||||||
|
mainObjectFileID: 2100000
|
||||||
|
userData:
|
||||||
|
assetBundleName:
|
||||||
|
assetBundleVariant:
|
||||||
@ -165,6 +165,8 @@ MonoBehaviour:
|
|||||||
acceleration: {x: 0, y: 0, z: 0}
|
acceleration: {x: 0, y: 0, z: 0}
|
||||||
nanoBrain: {fileID: 0}
|
nanoBrain: {fileID: 0}
|
||||||
id: 0
|
id: 0
|
||||||
|
red: {fileID: 2100000, guid: 2a7557e54580b6a8b976f12aa6cc761c, type: 2}
|
||||||
|
gray: {fileID: 2100000, guid: a79ccc131cb43254cb8575d1cedb537e, type: 2}
|
||||||
--- !u!114 &85370558829139006
|
--- !u!114 &85370558829139006
|
||||||
MonoBehaviour:
|
MonoBehaviour:
|
||||||
m_ObjectHideFlags: 0
|
m_ObjectHideFlags: 0
|
||||||
|
|||||||
@ -5,6 +5,7 @@ using UnityEngine;
|
|||||||
public class Boid : MonoBehaviour {
|
public class Boid : MonoBehaviour {
|
||||||
public static int BoundaryType = 1;
|
public static int BoundaryType = 1;
|
||||||
public static int BoidType = 2;
|
public static int BoidType = 2;
|
||||||
|
public static int BoidVelocityType =3;
|
||||||
|
|
||||||
public SwarmControl sc;
|
public SwarmControl sc;
|
||||||
public Vector3 velocity = Vector3.zero;
|
public Vector3 velocity = Vector3.zero;
|
||||||
@ -15,15 +16,20 @@ public class Boid : MonoBehaviour {
|
|||||||
public NanoBrainComponent nanoBrain;
|
public NanoBrainComponent nanoBrain;
|
||||||
public Receptor boundaryReceptor;
|
public Receptor boundaryReceptor;
|
||||||
public Receptor boidReceptor;
|
public Receptor boidReceptor;
|
||||||
|
public Receptor boidVelocityReceptor;
|
||||||
|
|
||||||
public int id;
|
public int id;
|
||||||
|
|
||||||
|
public Material red;
|
||||||
|
public Material gray;
|
||||||
|
|
||||||
void Awake() {
|
void Awake() {
|
||||||
this.id = this.GetInstanceID();
|
this.id = this.GetInstanceID();
|
||||||
|
|
||||||
nanoBrain = GetComponent<NanoBrainComponent>();
|
nanoBrain = GetComponent<NanoBrainComponent>();
|
||||||
boundaryReceptor = Perceptoid.GetReceptor(nanoBrain.brain, BoundaryType);
|
boundaryReceptor = Perceptoid.GetReceptor(nanoBrain.brain, BoundaryType);
|
||||||
boidReceptor = Perceptoid.GetReceptor(nanoBrain.brain, BoidType);
|
boidReceptor = Perceptoid.GetReceptor(nanoBrain.brain, BoidType);
|
||||||
|
boidVelocityReceptor = Perceptoid.GetReceptor(nanoBrain.brain, BoidVelocityType);
|
||||||
|
|
||||||
sc = FindFirstObjectByType<SwarmControl>();
|
sc = FindFirstObjectByType<SwarmControl>();
|
||||||
|
|
||||||
@ -39,11 +45,14 @@ public class Boid : MonoBehaviour {
|
|||||||
continue;
|
continue;
|
||||||
|
|
||||||
Vector3 localPosition = this.transform.InverseTransformPoint(neighbour.transform.position);
|
Vector3 localPosition = this.transform.InverseTransformPoint(neighbour.transform.position);
|
||||||
localPosition = localPosition.normalized * (localPosition.magnitude - sc.separationDistance);
|
//localPosition = localPosition.normalized * (localPosition.magnitude - sc.separationDistance);
|
||||||
//Debug.DrawRay(this.transform.position, this.transform.TransformDirection(localPosition), Color.magenta);
|
//Debug.DrawRay(this.transform.position, this.transform.TransformDirection(localPosition), Color.magenta);
|
||||||
|
|
||||||
|
Vector3 localVelocity = this.transform.InverseTransformVector(neighbour.velocity);
|
||||||
|
|
||||||
int thingId = neighbour.GetInstanceID();
|
int thingId = neighbour.GetInstanceID();
|
||||||
boidReceptor?.ProcessStimulus(thingId, localPosition);
|
boidReceptor?.ProcessStimulus(thingId, localPosition);
|
||||||
|
boidVelocityReceptor?.ProcessStimulus(thingId, localVelocity);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -55,6 +64,7 @@ public class Boid : MonoBehaviour {
|
|||||||
boundaryReceptor.ProcessStimulus(777, desiredLocalSpace);
|
boundaryReceptor.ProcessStimulus(777, desiredLocalSpace);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
Vector3 worldForce = this.transform.TransformDirection(nanoBrain.root.outputValue.ToVector3());
|
Vector3 worldForce = this.transform.TransformDirection(nanoBrain.root.outputValue.ToVector3());
|
||||||
|
|
||||||
this.velocity = (1 - sc.inertia) * (worldForce * Time.deltaTime) + sc.inertia * velocity;
|
this.velocity = (1 - sc.inertia) * (worldForce * Time.deltaTime) + sc.inertia * velocity;
|
||||||
@ -72,6 +82,19 @@ public class Boid : MonoBehaviour {
|
|||||||
}
|
}
|
||||||
|
|
||||||
nanoBrain.brain.UpdateNuclei();
|
nanoBrain.brain.UpdateNuclei();
|
||||||
|
|
||||||
|
Renderer renderer = GetComponentInChildren<Renderer>();
|
||||||
|
results = Physics.OverlapSphere(this.transform.position, 0.1f);
|
||||||
|
if (results.Length > 1) {
|
||||||
|
// string s= this.name;
|
||||||
|
// foreach (Collider c in results)
|
||||||
|
// s += " " + c.transform.parent.gameObject.name;
|
||||||
|
// Debug.Log(s);
|
||||||
|
renderer.sharedMaterial = red;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
renderer.sharedMaterial = gray;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@ -15,7 +15,7 @@ public class SwarmControl_Editor : Editor {
|
|||||||
foreach (NanoBrainObj brain in nanoBrains) {
|
foreach (NanoBrainObj brain in nanoBrains) {
|
||||||
UpdateWeight(brain, "Avoidance", swarmControl.avoidanceForce);
|
UpdateWeight(brain, "Avoidance", swarmControl.avoidanceForce);
|
||||||
UpdateWeight(brain, "Cohesion", swarmControl.cohesionForce);
|
UpdateWeight(brain, "Cohesion", swarmControl.cohesionForce);
|
||||||
//UpdateWeight(brain, "Separation", swarmControl.separationDistance);
|
UpdateWeight(brain, "Separation", swarmControl.separationForce);
|
||||||
UpdateWeight(brain, "Alignment", swarmControl.alignmentForce);
|
UpdateWeight(brain, "Alignment", swarmControl.alignmentForce);
|
||||||
}
|
}
|
||||||
Debug.Log("Updated weights");
|
Debug.Log("Updated weights");
|
||||||
|
|||||||
@ -8,6 +8,7 @@ public class SwarmControl : MonoBehaviour
|
|||||||
public float inertia = 0.1f;
|
public float inertia = 0.1f;
|
||||||
public float alignmentForce = 0.0f;
|
public float alignmentForce = 0.0f;
|
||||||
public float cohesionForce = 10.0f;
|
public float cohesionForce = 10.0f;
|
||||||
|
public float separationForce = 5.0f;
|
||||||
public float avoidanceForce = 5.0f;
|
public float avoidanceForce = 5.0f;
|
||||||
public float separationDistance = 0.5f;
|
public float separationDistance = 0.5f;
|
||||||
// public float bodyForce = 20;
|
// public float bodyForce = 20;
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user