Placing home pheromones

This commit is contained in:
Pascal Serrarens 2026-03-10 11:49:56 +01:00
parent 481829c873
commit 88d5eb565d
8 changed files with 79 additions and 30 deletions

View File

@ -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

View File

@ -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;

View File

@ -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);
}
}
}

View File

@ -53,7 +53,7 @@ public class ClusterInspector : Editor {
inspectorContainer = new VisualElement {
name = "inspector",
style = {
width = 300,
width = 500,
flexGrow = 0
}
};

View File

@ -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) {

View File

@ -1,5 +1,9 @@
using UnityEngine;
namespace Passer.CreatureControl {
public class Food : Odorant
{
}
}

View File

@ -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;
}
}
}

View File

@ -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);
}
}
}
}
}