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));
|
||||
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
|
||||
|
||||
@ -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;
|
||||
|
||||
@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@ -53,7 +53,7 @@ public class ClusterInspector : Editor {
|
||||
inspectorContainer = new VisualElement {
|
||||
name = "inspector",
|
||||
style = {
|
||||
width = 300,
|
||||
width = 500,
|
||||
flexGrow = 0
|
||||
}
|
||||
};
|
||||
|
||||
@ -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) {
|
||||
|
||||
@ -1,5 +1,9 @@
|
||||
using UnityEngine;
|
||||
|
||||
namespace Passer.CreatureControl {
|
||||
|
||||
public class Food : Odorant
|
||||
{
|
||||
}
|
||||
|
||||
}
|
||||
@ -1,5 +1,7 @@
|
||||
using UnityEngine;
|
||||
|
||||
namespace Passer.CreatureControl {
|
||||
|
||||
public class Odorant : MonoBehaviour {
|
||||
public float strength = 1;
|
||||
|
||||
@ -8,3 +10,5 @@ public class Odorant : MonoBehaviour {
|
||||
return intensity;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@ -1,8 +1,9 @@
|
||||
using UnityEngine;
|
||||
|
||||
namespace Passer.CreatureControl {
|
||||
|
||||
public class Pheromone : Odorant {
|
||||
//public float strength = 30; // seconds
|
||||
public float duration = 30;
|
||||
public float duration = 30; // seconds
|
||||
|
||||
public enum Type {
|
||||
Unknown = 0,
|
||||
@ -11,7 +12,6 @@ public class Pheromone : Odorant {
|
||||
};
|
||||
public Type type = 0;
|
||||
|
||||
// Update is called once per frame
|
||||
void Update() {
|
||||
this.strength -= (Time.deltaTime / duration);
|
||||
if (this.strength < 0) {
|
||||
@ -20,3 +20,5 @@ public class Pheromone : Odorant {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
Loading…
x
Reference in New Issue
Block a user