diff --git a/CreatureControl/Editor/Scripts/Insect/Insect_Editor.cs b/CreatureControl/Editor/Scripts/Insect/Insect_Editor.cs index a0cf1fa..e2a08d9 100644 --- a/CreatureControl/Editor/Scripts/Insect/Insect_Editor.cs +++ b/CreatureControl/Editor/Scripts/Insect/Insect_Editor.cs @@ -79,6 +79,31 @@ namespace Passer.CreatureControl { SerializedProperty animatorControllerProp = targetRigObj.FindProperty(nameof(InsectRig.animator)); animatorControllerProp.objectReferenceValue = (Animator)EditorGUILayout.ObjectField(text, animatorControllerProp.objectReferenceValue, typeof(Animator), true); + + EditorGUI.indentLevel++; + ForwardSpeedInspector(); + RotationSpeedInspector(); + EditorGUI.indentLevel--; + } + + private void ForwardSpeedInspector() { + GUIContent text = new( + "Forward speed", + "The maximum forward speed of the ant" + ); + + SerializedProperty forwardSpeedProp = serializedObject.FindProperty(nameof(Insect.forwardSpeed)); + forwardSpeedProp.floatValue = EditorGUILayout.FloatField(text, forwardSpeedProp.floatValue); + } + + private void RotationSpeedInspector() { + GUIContent text = new( + "Rotation speed", + "The maximum rotation speed of the ant" + ); + + SerializedProperty rotationSpeedProp = serializedObject.FindProperty(nameof(Insect.rotationSpeed)); + rotationSpeedProp.floatValue = EditorGUILayout.FloatField(text, rotationSpeedProp.floatValue); } #endregion Inspector diff --git a/CreatureControl/Runtime/Scripts/Insect/Insect.cs b/CreatureControl/Runtime/Scripts/Insect/Insect.cs index 78869e6..4d0a88a 100644 --- a/CreatureControl/Runtime/Scripts/Insect/Insect.cs +++ b/CreatureControl/Runtime/Scripts/Insect/Insect.cs @@ -4,6 +4,9 @@ namespace Passer.CreatureControl { public InsectRig insectRig; + public float forwardSpeed = 1; + public float rotationSpeed = 1; + public Leg leftFrontLeg; public Leg leftMiddleLeg; public Leg leftHindLeg; diff --git a/Editor/Scripts/Ant_Editor.cs b/Editor/Scripts/Ant_Editor.cs index 8b211f3..1593610 100644 --- a/Editor/Scripts/Ant_Editor.cs +++ b/Editor/Scripts/Ant_Editor.cs @@ -1,4 +1,5 @@ using UnityEditor; +using UnityEngine; namespace Passer.CreatureControl { @@ -12,6 +13,17 @@ namespace Passer.CreatureControl { base.OnEnable(); } + + public override void OnInspectorGUI() { + base.OnInspectorGUI(); + + HomePheromonePrefabInspector(); + } + + private void HomePheromonePrefabInspector() { + SerializedProperty homePheromonePrefabProp = serializedObject.FindProperty(nameof(Ant.homePheromonePrefab)); + homePheromonePrefabProp.objectReferenceValue = (GameObject) EditorGUILayout.ObjectField("Home Pheromone Prefab", homePheromonePrefabProp.objectReferenceValue, typeof(GameObject), true); + } } } \ No newline at end of file diff --git a/NanoBrain/Editor/ClusterInspector.cs b/NanoBrain/Editor/ClusterInspector.cs index 5aeb9c9..2999938 100644 --- a/NanoBrain/Editor/ClusterInspector.cs +++ b/NanoBrain/Editor/ClusterInspector.cs @@ -53,7 +53,7 @@ public class ClusterInspector : Editor { inspectorContainer = new VisualElement { name = "inspector", style = { - width = 300, + width = 500, flexGrow = 0 } }; diff --git a/Runtime/Scripts/Ant.cs b/Runtime/Scripts/Ant.cs index cd5c03a..b7ec24e 100644 --- a/Runtime/Scripts/Ant.cs +++ b/Runtime/Scripts/Ant.cs @@ -27,8 +27,6 @@ namespace Passer.CreatureControl { public Receptor homeReceptor; public Animator animator; - public float forwardSpeed = 1; - public float rotationSpeed = 1; public Vector3 linearVelocity; public Vector3 angularVelocity; @@ -82,11 +80,11 @@ namespace Passer.CreatureControl { void PlaceFoodPheromone() { GameObject pheromoneObj = Instantiate(foodPheromonePrefab); - pheromoneObj.transform.position = this.transform.position; + pheromoneObj.transform.position = this.model.position; } void PlaceHomePheromone() { GameObject pheromoneObj = Instantiate(homePheromonePrefab); - pheromoneObj.transform.position = this.transform.position; + pheromoneObj.transform.position = this.model.position; } // Update is called once per frame @@ -103,7 +101,7 @@ namespace Passer.CreatureControl { this.linearVelocity = (1 - inertia) * (Time.deltaTime * localForce.normalized) + inertia * this.linearVelocity; this.linearVelocity = this.linearVelocity.normalized * 0.2f; - this.animator.SetFloat("Forward", this.linearVelocity.z * this.forwardSpeed); + this.animator.SetFloat("Forward", this.forwardSpeed); //this.linearVelocity.z * this.forwardSpeed); // Rotate towards the movement direction if (this.linearVelocity != Vector3.zero) { @@ -133,14 +131,15 @@ namespace Passer.CreatureControl { if (Time.time - lastBeatTime >= beatInterval) { lastBeatTime = Time.time; beat?.SetBias(Vector3.one); //, 0); + + float randomAngle = Random.Range(-smellAngle, smellAngle); + Vector3 randomDirection = Quaternion.AngleAxis(randomAngle, Vector3.up) * Vector3.forward * 1.01f; + pheromoneSteering?.SetBias(randomDirection); //, 0, "random"); } } void UpdateSmell() { // To generate random basic movement, we add a small with a random direction with low intensity - float randomAngle = Random.Range(-smellAngle, smellAngle); - Vector3 randomDirection = Quaternion.AngleAxis(randomAngle, Vector3.up) * Vector3.forward * 0.01f; - pheromoneSteering?.SetBias(randomDirection); //, 0, "random"); Collider[] colliders = Physics.OverlapSphere(this.transform.position, smellRadius); foreach (Collider collider in colliders) { diff --git a/Runtime/Scripts/Food.cs b/Runtime/Scripts/Food.cs index d9672b5..2d4c443 100644 --- a/Runtime/Scripts/Food.cs +++ b/Runtime/Scripts/Food.cs @@ -1,5 +1,9 @@ using UnityEngine; +namespace Passer.CreatureControl { + public class Food : Odorant { } + +} \ No newline at end of file diff --git a/Runtime/Scripts/Odorant.cs b/Runtime/Scripts/Odorant.cs index 14cda79..7e4b8f3 100644 --- a/Runtime/Scripts/Odorant.cs +++ b/Runtime/Scripts/Odorant.cs @@ -1,10 +1,14 @@ using UnityEngine; -public class Odorant : MonoBehaviour { - public float strength = 1; +namespace Passer.CreatureControl { - public float StrengthAt(float distance) { - float intensity = this.strength * (1 / distance); - return intensity; + public class Odorant : MonoBehaviour { + public float strength = 1; + + public float StrengthAt(float distance) { + float intensity = this.strength * (1 / distance); + return intensity; + } } + } \ No newline at end of file diff --git a/Runtime/Scripts/Pheromone.cs b/Runtime/Scripts/Pheromone.cs index 2e5b488..3dd260f 100644 --- a/Runtime/Scripts/Pheromone.cs +++ b/Runtime/Scripts/Pheromone.cs @@ -1,22 +1,24 @@ using UnityEngine; -public class Pheromone : Odorant { - //public float strength = 30; // seconds - public float duration = 30; +namespace Passer.CreatureControl { - public enum Type { - Unknown = 0, - Food = 82, - Home = 83 - }; - public Type type = 0; + public class Pheromone : Odorant { + public float duration = 30; // seconds - // Update is called once per frame - void Update() { - this.strength -= (Time.deltaTime / duration); - if (this.strength < 0) { - // Debug.Log($"destroyed {this.name}"); - Destroy(this.gameObject); + public enum Type { + Unknown = 0, + Food = 82, + Home = 83 + }; + public Type type = 0; + + void Update() { + this.strength -= (Time.deltaTime / duration); + if (this.strength < 0) { + // Debug.Log($"destroyed {this.name}"); + Destroy(this.gameObject); + } } } -} + +} \ No newline at end of file