Placing home pheromones
This commit is contained in:
parent
481829c873
commit
88d5eb565d
@ -79,6 +79,31 @@ namespace Passer.CreatureControl {
|
|||||||
|
|
||||||
SerializedProperty animatorControllerProp = targetRigObj.FindProperty(nameof(InsectRig.animator));
|
SerializedProperty animatorControllerProp = targetRigObj.FindProperty(nameof(InsectRig.animator));
|
||||||
animatorControllerProp.objectReferenceValue = (Animator)EditorGUILayout.ObjectField(text, animatorControllerProp.objectReferenceValue, typeof(Animator), true);
|
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
|
#endregion Inspector
|
||||||
|
|||||||
@ -4,6 +4,9 @@ namespace Passer.CreatureControl {
|
|||||||
|
|
||||||
public InsectRig insectRig;
|
public InsectRig insectRig;
|
||||||
|
|
||||||
|
public float forwardSpeed = 1;
|
||||||
|
public float rotationSpeed = 1;
|
||||||
|
|
||||||
public Leg leftFrontLeg;
|
public Leg leftFrontLeg;
|
||||||
public Leg leftMiddleLeg;
|
public Leg leftMiddleLeg;
|
||||||
public Leg leftHindLeg;
|
public Leg leftHindLeg;
|
||||||
|
|||||||
@ -1,4 +1,5 @@
|
|||||||
using UnityEditor;
|
using UnityEditor;
|
||||||
|
using UnityEngine;
|
||||||
|
|
||||||
namespace Passer.CreatureControl {
|
namespace Passer.CreatureControl {
|
||||||
|
|
||||||
@ -12,6 +13,17 @@ namespace Passer.CreatureControl {
|
|||||||
|
|
||||||
base.OnEnable();
|
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);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
@ -53,7 +53,7 @@ public class ClusterInspector : Editor {
|
|||||||
inspectorContainer = new VisualElement {
|
inspectorContainer = new VisualElement {
|
||||||
name = "inspector",
|
name = "inspector",
|
||||||
style = {
|
style = {
|
||||||
width = 300,
|
width = 500,
|
||||||
flexGrow = 0
|
flexGrow = 0
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|||||||
@ -27,8 +27,6 @@ namespace Passer.CreatureControl {
|
|||||||
public Receptor homeReceptor;
|
public Receptor homeReceptor;
|
||||||
|
|
||||||
public Animator animator;
|
public Animator animator;
|
||||||
public float forwardSpeed = 1;
|
|
||||||
public float rotationSpeed = 1;
|
|
||||||
public Vector3 linearVelocity;
|
public Vector3 linearVelocity;
|
||||||
public Vector3 angularVelocity;
|
public Vector3 angularVelocity;
|
||||||
|
|
||||||
@ -82,11 +80,11 @@ namespace Passer.CreatureControl {
|
|||||||
|
|
||||||
void PlaceFoodPheromone() {
|
void PlaceFoodPheromone() {
|
||||||
GameObject pheromoneObj = Instantiate(foodPheromonePrefab);
|
GameObject pheromoneObj = Instantiate(foodPheromonePrefab);
|
||||||
pheromoneObj.transform.position = this.transform.position;
|
pheromoneObj.transform.position = this.model.position;
|
||||||
}
|
}
|
||||||
void PlaceHomePheromone() {
|
void PlaceHomePheromone() {
|
||||||
GameObject pheromoneObj = Instantiate(homePheromonePrefab);
|
GameObject pheromoneObj = Instantiate(homePheromonePrefab);
|
||||||
pheromoneObj.transform.position = this.transform.position;
|
pheromoneObj.transform.position = this.model.position;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Update is called once per frame
|
// 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 = (1 - inertia) * (Time.deltaTime * localForce.normalized) + inertia * this.linearVelocity;
|
||||||
this.linearVelocity = this.linearVelocity.normalized * 0.2f;
|
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
|
// Rotate towards the movement direction
|
||||||
if (this.linearVelocity != Vector3.zero) {
|
if (this.linearVelocity != Vector3.zero) {
|
||||||
@ -133,14 +131,15 @@ namespace Passer.CreatureControl {
|
|||||||
if (Time.time - lastBeatTime >= beatInterval) {
|
if (Time.time - lastBeatTime >= beatInterval) {
|
||||||
lastBeatTime = Time.time;
|
lastBeatTime = Time.time;
|
||||||
beat?.SetBias(Vector3.one); //, 0);
|
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() {
|
void UpdateSmell() {
|
||||||
// To generate random basic movement, we add a small with a random direction with low intensity
|
// 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);
|
Collider[] colliders = Physics.OverlapSphere(this.transform.position, smellRadius);
|
||||||
foreach (Collider collider in colliders) {
|
foreach (Collider collider in colliders) {
|
||||||
|
|||||||
@ -1,5 +1,9 @@
|
|||||||
using UnityEngine;
|
using UnityEngine;
|
||||||
|
|
||||||
|
namespace Passer.CreatureControl {
|
||||||
|
|
||||||
public class Food : Odorant
|
public class Food : Odorant
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@ -1,10 +1,14 @@
|
|||||||
using UnityEngine;
|
using UnityEngine;
|
||||||
|
|
||||||
public class Odorant : MonoBehaviour {
|
namespace Passer.CreatureControl {
|
||||||
public float strength = 1;
|
|
||||||
|
|
||||||
public float StrengthAt(float distance) {
|
public class Odorant : MonoBehaviour {
|
||||||
float intensity = this.strength * (1 / distance);
|
public float strength = 1;
|
||||||
return intensity;
|
|
||||||
|
public float StrengthAt(float distance) {
|
||||||
|
float intensity = this.strength * (1 / distance);
|
||||||
|
return intensity;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
@ -1,22 +1,24 @@
|
|||||||
using UnityEngine;
|
using UnityEngine;
|
||||||
|
|
||||||
public class Pheromone : Odorant {
|
namespace Passer.CreatureControl {
|
||||||
//public float strength = 30; // seconds
|
|
||||||
public float duration = 30;
|
|
||||||
|
|
||||||
public enum Type {
|
public class Pheromone : Odorant {
|
||||||
Unknown = 0,
|
public float duration = 30; // seconds
|
||||||
Food = 82,
|
|
||||||
Home = 83
|
|
||||||
};
|
|
||||||
public Type type = 0;
|
|
||||||
|
|
||||||
// Update is called once per frame
|
public enum Type {
|
||||||
void Update() {
|
Unknown = 0,
|
||||||
this.strength -= (Time.deltaTime / duration);
|
Food = 82,
|
||||||
if (this.strength < 0) {
|
Home = 83
|
||||||
// Debug.Log($"destroyed {this.name}");
|
};
|
||||||
Destroy(this.gameObject);
|
public Type type = 0;
|
||||||
|
|
||||||
|
void Update() {
|
||||||
|
this.strength -= (Time.deltaTime / duration);
|
||||||
|
if (this.strength < 0) {
|
||||||
|
// Debug.Log($"destroyed {this.name}");
|
||||||
|
Destroy(this.gameObject);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
}
|
||||||
Loading…
x
Reference in New Issue
Block a user