Initial Ant setup

This commit is contained in:
Pascal Serrarens 2026-03-09 13:08:31 +01:00
parent af2fa77add
commit c1dcc83827
64 changed files with 5954 additions and 340 deletions

8
Animation.meta Normal file
View File

@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: 129468cd2362336149b803fa12f962c0
folderAsset: yes
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

View File

@ -0,0 +1,146 @@
%YAML 1.1
%TAG !u! tag:unity3d.com,2011:
--- !u!206 &-7807188484574405462
BlendTree:
m_ObjectHideFlags: 1
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_Name: Blend Tree
m_Childs:
- serializedVersion: 2
m_Motion: {fileID: 7400000, guid: b8a731a1533b8c960b3f3688d4922a24, type: 2}
m_Threshold: 0
m_Position: {x: 0, y: 1}
m_TimeScale: 10
m_CycleOffset: 0
m_DirectBlendParameter: Forward
m_Mirror: 0
- serializedVersion: 2
m_Motion: {fileID: 7400000, guid: ab82ff68e62ea3b1c8e6523f8d46c142, type: 2}
m_Threshold: 0.5
m_Position: {x: -1, y: 0}
m_TimeScale: 5
m_CycleOffset: 0
m_DirectBlendParameter: Forward
m_Mirror: 0
- serializedVersion: 2
m_Motion: {fileID: 7400000, guid: 91229db5e929c379bbfd5bf417848488, type: 2}
m_Threshold: 1
m_Position: {x: 1, y: 0}
m_TimeScale: 5
m_CycleOffset: 0
m_DirectBlendParameter: Forward
m_Mirror: 0
m_BlendParameter: Rotate
m_BlendParameterY: Forward
m_MinThreshold: 0
m_MaxThreshold: 1
m_UseAutomaticThresholds: 1
m_NormalizedBlendValues: 0
m_BlendType: 3
--- !u!91 &9100000
AnimatorController:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_Name: AntAnimator
serializedVersion: 5
m_AnimatorParameters:
- m_Name: Forward
m_Type: 1
m_DefaultFloat: 0
m_DefaultInt: 0
m_DefaultBool: 0
m_Controller: {fileID: 9100000}
- m_Name: Rotate
m_Type: 1
m_DefaultFloat: 0
m_DefaultInt: 0
m_DefaultBool: 0
m_Controller: {fileID: 9100000}
m_AnimatorLayers:
- serializedVersion: 5
m_Name: Base Layer
m_StateMachine: {fileID: 2310030155210667225}
m_Mask: {fileID: 0}
m_Motions: []
m_Behaviours: []
m_BlendingMode: 0
m_SyncedLayerIndex: -1
m_DefaultWeight: 0
m_IKPass: 0
m_SyncedLayerAffectsTiming: 0
m_Controller: {fileID: 9100000}
--- !u!1101 &2088305737403053393
AnimatorStateTransition:
m_ObjectHideFlags: 1
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_Name:
m_Conditions: []
m_DstStateMachine: {fileID: 0}
m_DstState: {fileID: 0}
m_Solo: 0
m_Mute: 0
m_IsExit: 1
serializedVersion: 3
m_TransitionDuration: 0.25
m_TransitionOffset: 0
m_ExitTime: 0.75
m_HasExitTime: 1
m_HasFixedDuration: 1
m_InterruptionSource: 0
m_OrderedInterruption: 1
m_CanTransitionToSelf: 1
--- !u!1107 &2310030155210667225
AnimatorStateMachine:
serializedVersion: 6
m_ObjectHideFlags: 1
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_Name: Base Layer
m_ChildStates:
- serializedVersion: 1
m_State: {fileID: 5197032680816450026}
m_Position: {x: 80, y: 250, z: 0}
m_ChildStateMachines: []
m_AnyStateTransitions: []
m_EntryTransitions: []
m_StateMachineTransitions: {}
m_StateMachineBehaviours: []
m_AnyStatePosition: {x: 50, y: 20, z: 0}
m_EntryPosition: {x: 50, y: 120, z: 0}
m_ExitPosition: {x: 40, y: 500, z: 0}
m_ParentStateMachinePosition: {x: 800, y: 20, z: 0}
m_DefaultState: {fileID: 5197032680816450026}
--- !u!1102 &5197032680816450026
AnimatorState:
serializedVersion: 6
m_ObjectHideFlags: 1
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_Name: AntWalk
m_Speed: 1
m_CycleOffset: 0
m_Transitions:
- {fileID: 2088305737403053393}
m_StateMachineBehaviours: []
m_Position: {x: 50, y: 50, z: 0}
m_IKOnFeet: 0
m_WriteDefaultValues: 1
m_Mirror: 0
m_SpeedParameterActive: 0
m_MirrorParameterActive: 0
m_CycleOffsetParameterActive: 0
m_TimeParameterActive: 0
m_Motion: {fileID: -7807188484574405462}
m_Tag:
m_SpeedParameter:
m_MirrorParameter:
m_CycleOffsetParameter:
m_TimeParameter:

View File

@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: d4b9f32bef604abd5953647ad53ca0f7
NativeFormatImporter:
externalObjects: {}
mainObjectFileID: 9100000
userData:
assetBundleName:
assetBundleVariant:

1303
Animation/AntRotateLeft.anim Normal file

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: ab82ff68e62ea3b1c8e6523f8d46c142
NativeFormatImporter:
externalObjects: {}
mainObjectFileID: 0
userData:
assetBundleName:
assetBundleVariant:

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: 91229db5e929c379bbfd5bf417848488
NativeFormatImporter:
externalObjects: {}
mainObjectFileID: 0
userData:
assetBundleName:
assetBundleVariant:

1181
Animation/AntWalk.anim Normal file

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: b8a731a1533b8c960b3f3688d4922a24
NativeFormatImporter:
externalObjects: {}
mainObjectFileID: 0
userData:
assetBundleName:
assetBundleVariant:

8
CreatureControl.meta Normal file
View File

@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: ead5f2201e9c95549acb5631aad16b67
folderAsset: yes
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

View File

@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: 9d715489a5eda538a959b6e4cb89d1bc
folderAsset: yes
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

View File

@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: c9680189a3ff3bf0c9d72edaa1aa07e4
folderAsset: yes
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

View File

@ -0,0 +1,44 @@
using UnityEditor;
using UnityEditor.SceneManagement;
using UnityEngine;
namespace Passer.CreatureControl {
[CustomEditor(typeof(Creature), true)]
public class Creature_Editor : Editor {
protected Creature creature;
public virtual void OnEnable() {
creature = (Creature)target;
if (creature == null)
return;
if (!IsPrefab(creature))
InitTargets(creature);
}
public static bool IsPrefab(Creature creature) {
PrefabStage prefabStage = PrefabStageUtility.GetPrefabStage(creature.gameObject);
return prefabStage != null;
}
#region Targets
protected virtual void InitTargets(Creature creature) {
TargetsRigInspector(creature, "TargetRig");
}
protected void TargetsRigInspector(Creature creature, string targetRigResourceName) {
Creature.CheckTargetRig(creature, targetRigResourceName);
if (creature.targetRig.gameObject.hideFlags != HideFlags.None) {
creature.targetRig.gameObject.hideFlags = HideFlags.None;
EditorApplication.DirtyHierarchyWindowSorting();
}
}
}
#endregion Targets
}

View File

@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: e21e842527e8292c1a7002c75825bc7b
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: 7e4dae7701b15cb018fbd090cc5c6c0b
folderAsset: yes
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

View File

@ -0,0 +1,79 @@
using UnityEditor;
using UnityEngine;
namespace Passer.CreatureControl {
[CustomEditor(typeof(Insect), true)]
public class Insect_Editor : Creature_Editor {
protected Insect insect;
public override void OnEnable() {
base.OnEnable();
insect = target as Insect;
}
public override void OnInspectorGUI() {
EditorGUIUtility.wideMode = true;
serializedObject.Update();
SerializedProperty targetRigProp = serializedObject.FindProperty(nameof(Creature.targetRig));
targetRigProp.objectReferenceValue = (TargetRig)EditorGUILayout.ObjectField("Target Rig", targetRigProp.objectReferenceValue, typeof(TargetRig), true);
TargetsInspector(insect);
// EditorGUILayout.Space();
// SerializedProperty leftFrontLegProp = serializedObject.FindProperty(nameof(Insect.leftFrontLeg));
// Leg_Editor.Inspector(leftFrontLegProp);
// SerializedProperty leftMiddleLegProp = serializedObject.FindProperty(nameof(Insect.leftMiddleLeg));
// Leg_Editor.Inspector(leftMiddleLegProp);
// SerializedProperty leftHindLegProp = serializedObject.FindProperty(nameof(Insect.leftHindLeg));
// Leg_Editor.Inspector(leftHindLegProp);
// SerializedProperty rightFrontLegProp = serializedObject.FindProperty(nameof(Insect.rightFrontLeg));
// Leg_Editor.Inspector(rightFrontLegProp);
// SerializedProperty rightMiddleLegProp = serializedObject.FindProperty(nameof(Insect.rightMiddleLeg));
// Leg_Editor.Inspector(rightMiddleLegProp);
// SerializedProperty rightHindLegProp = serializedObject.FindProperty(nameof(Insect.rightHindLeg));
// Leg_Editor.Inspector(rightHindLegProp);
serializedObject.ApplyModifiedProperties();
}
static bool showTargets;
private void TargetsInspector(Insect insect) {
GUIContent text = new(
"Targets",
"The target transforms controlling the body parts"
);
showTargets = EditorGUILayout.Foldout(showTargets, text, true);
if (showTargets) {
EditorGUI.indentLevel++;
SerializedProperty leftFrontLegProp = serializedObject.FindProperty(nameof(Insect.leftFrontLeg));
Leg_Editor.Inspector(leftFrontLegProp);
SerializedProperty leftMiddleLegProp = serializedObject.FindProperty(nameof(Insect.leftMiddleLeg));
Leg_Editor.Inspector(leftMiddleLegProp);
SerializedProperty leftHindLegProp = serializedObject.FindProperty(nameof(Insect.leftHindLeg));
Leg_Editor.Inspector(leftHindLegProp);
SerializedProperty rightFrontLegProp = serializedObject.FindProperty(nameof(Insect.rightFrontLeg));
Leg_Editor.Inspector(rightFrontLegProp);
SerializedProperty rightMiddleLegProp = serializedObject.FindProperty(nameof(Insect.rightMiddleLeg));
Leg_Editor.Inspector(rightMiddleLegProp);
SerializedProperty rightHindLegProp = serializedObject.FindProperty(nameof(Insect.rightHindLeg));
Leg_Editor.Inspector(rightHindLegProp);
// insect.headTarget = (HeadTarget)HumanoidTarget_Editor.Inspector(insect.headTarget, "Head Target");
// insect.leftHandTarget = (HandTarget)HandTarget_Editor.Inspector(insect.leftHandTarget, "Left Hand Target");
// insect.rightHandTarget = (HandTarget)HandTarget_Editor.Inspector(insect.rightHandTarget, "Right Hand Target");
// insect.hipsTarget = (HipsTarget)HumanoidTarget_Editor.Inspector(insect.hipsTarget, "Hips Target");
// insect.leftFootTarget = (FootTarget)FootTarget_Editor.Inspector(insect.leftFootTarget, "Left Foot Target");
// insect.rightFootTarget = (FootTarget)FootTarget_Editor.Inspector(insect.rightFootTarget, "Right Foot Target");
EditorGUI.indentLevel--;
}
}
}
}

View File

@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: fd27aa19166e492b582b506dc25eb605
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@ -0,0 +1,75 @@
using UnityEditor;
using UnityEngine;
namespace Passer.CreatureControl {
public class Leg_Editor {
//private string label = "";
private static bool showfield = false;
public void Enable() {
}
public static void Inspector(SerializedProperty legProp) {
GUIStyle foldoutStyle = new(EditorStyles.foldout) {
margin = EditorStyles.objectField.margin
};
EditorGUILayout.BeginHorizontal();
string legName = ConvertCamelCase(legProp.name);
showfield = EditorGUILayout.Foldout(showfield, legName, true, foldoutStyle);
SerializedProperty femurProp = legProp.FindPropertyRelative(nameof(Leg.femur));
SerializedProperty tibiaProp = legProp.FindPropertyRelative(nameof(Leg.tibia));
SerializedProperty tarsusProp = legProp.FindPropertyRelative(nameof(Leg.tarsus));
Transform newFemur = (Transform)EditorGUILayout.ObjectField(femurProp.objectReferenceValue, typeof(Transform), true);
if (newFemur != femurProp.objectReferenceValue) {
femurProp.objectReferenceValue = newFemur;
if (newFemur != null) {
if (tibiaProp.objectReferenceValue == null && newFemur.childCount == 1)
tibiaProp.objectReferenceValue = newFemur.GetChild(0);
Transform tibia = (Transform)tibiaProp.objectReferenceValue;
if (tibia != null) {
if (tarsusProp.objectReferenceValue == null && tibia.childCount == 1)
tarsusProp.objectReferenceValue = tibia.GetChild(0);
}
}
}
EditorGUILayout.EndHorizontal();
if (femurProp.objectReferenceValue != null && tibiaProp.objectReferenceValue == null)
showfield = true;
if (showfield) {
EditorGUI.indentLevel++;
tibiaProp.objectReferenceValue = (Transform)EditorGUILayout.ObjectField("Lower Leg", tibiaProp.objectReferenceValue, typeof(Transform), true);
tarsusProp.objectReferenceValue = (Transform)EditorGUILayout.ObjectField("Foot", tarsusProp.objectReferenceValue, typeof(Transform), true);
EditorGUI.indentLevel--;
}
}
private static string ConvertCamelCase(string text) {
if (string.IsNullOrEmpty(text))
return text;
System.Text.StringBuilder result = new();
for (int i = 0; i < text.Length; i++) {
// Add a space before uppercase characters
if (char.IsUpper(text[i]) && i > 0)
result.Append(' ');
// Add the character to the result
result.Append(text[i]);
}
// Capitalize the first character of the result
if (result.Length > 0)
result[0] = char.ToUpper(result[0]);
return result.ToString();
}
}
}

View File

@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 32630932c64073f2d87d6502c6751fe1
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: ffcfc0e0e1a219581bc4d2bb33d40bd7
folderAsset: yes
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

View File

@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: e7da2341c34bff8169b3669cc9e20463
folderAsset: yes
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

View File

@ -0,0 +1,26 @@
using UnityEngine;
namespace Passer.CreatureControl {
public class Creature : MonoBehaviour {
/// <summary>The target bones rig</summary>
/// The target bones rig contain the target pose of the creature
/// The creature movements will try to move the creature such that the target pose is reached
/// as closely as possible
public TargetRig targetRig;
/// <summary>Match the target rig transform to the humanoid transform</summary>
public static void CheckTargetRig(Creature creature, string targetRigResourceName) {
if (creature.targetRig == null) {
GameObject targetsRigPrefab = Resources.Load<GameObject>(targetRigResourceName);
GameObject targetRig = Instantiate(targetsRigPrefab);
targetRig.name = "Target Rig";
targetRig.transform.SetPositionAndRotation(creature.transform.position, creature.transform.rotation);
targetRig.transform.SetParent(creature.transform);
creature.targetRig = targetRig.GetComponent<TargetRig>();
}
}
}
}

View File

@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 77c2897bce0332255bd076aab62e46d9
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: 85f3225e01cd157769e2faf0e722846f
folderAsset: yes
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

View File

@ -0,0 +1,13 @@
namespace Passer.CreatureControl {
public class Insect : Creature {
public Leg leftFrontLeg;
public Leg leftMiddleLeg;
public Leg leftHindLeg;
public Leg rightFrontLeg;
public Leg rightMiddleLeg;
public Leg rightHindLeg;
}
}

View File

@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 01b14620016fc2bfdb8a58d81e0396a3
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@ -0,0 +1,8 @@
using UnityEngine;
[System.Serializable]
public class Leg {
public Transform femur; // UpperLeg, Thigh
public Transform tibia; // LowerLeg, Shank
public Transform tarsus; // Foot
}

View File

@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 90a2688565fe3b05aba7cc9f9d70168c
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@ -0,0 +1,14 @@
using UnityEngine;
namespace Passer.CreatureControl {
public class LegTarget : MonoBehaviour {
public TargetLeg leg;
public virtual void OnDrawGizmosSelected() {
if (leg != null)
leg.OnDrawGizmosSelected();
}
}
}

View File

@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: fda62ae0dd837da8cb37ba5c7396c6a3
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@ -0,0 +1,168 @@
using UnityEngine;
namespace Passer.CreatureControl {
[System.Serializable]
public class TargetLeg : MonoBehaviour {
public Transform femurTarget; // UpperLeg, Thigh
public Transform tibiaTarget; // LowerLeg, Shank
public Transform tarsusTarget; // Foot
public Transform target; // for the tarsus
protected LegTarget legTarget;
public Quaternion targetToBoneFemur;
public Quaternion targetToBoneTibia;
public virtual void OnDrawGizmosSelected() {
if (target != null && legTarget == null) {
legTarget = target.GetComponent<LegTarget>();
if (legTarget == null)
legTarget = target.gameObject.AddComponent<LegTarget>();
legTarget.leg = this;
}
Gizmos.color = Color.white;
if (this.femurTarget != null && this.tibiaTarget != null)
Gizmos.DrawLine(this.femurTarget.position, this.tibiaTarget.position);
if (tibiaTarget != null && this.tarsusTarget != null)
Gizmos.DrawLine(this.tibiaTarget.position, this.tarsusTarget.position);
if (this.enabled)
PoseLimb();
}
public void PoseLimb() {
if (target == null)
return;
Quaternion femurOrientation = FemurRotation(target.position);
Quaternion tibiaOrientation = TibiaRotation(target.position);
Quaternion tarsusrientation = TarsusRotation(target.rotation);
SetFemurOrientation(femurTarget, femurOrientation);
SetTibiaOrientation(tibiaTarget, tibiaOrientation);
SetTarsusOrientation(tarsusTarget, tarsusrientation);
}
protected Quaternion FemurRotation(Vector3 targetPosition) {
if (this.femurTarget == null || this.tibiaTarget == null || this.tarsusTarget == null)
return Quaternion.identity;
Vector3 toTarget = targetPosition - this.femurTarget.position;
// Debug.DrawRay(femur.position, toTarget, Color.magenta);
float targetDistance = toTarget.magnitude;
float femurLength = Vector3.Distance(this.femurTarget.position, this.tibiaTarget.position);
float tibiaLength = Vector3.Distance(this.tibiaTarget.position, this.tarsusTarget.position);
float hipAngle = CosineRule(targetDistance, femurLength, tibiaLength);
// NaN happens when the distance to the footTarget is longer than the length of the leg
// We will stretch the leg full then (angle = 0)
if (float.IsNaN(hipAngle))
hipAngle = 0;
Quaternion femurOrientation = Quaternion.LookRotation(toTarget, Vector3.up);
femurOrientation = Quaternion.AngleAxis(hipAngle, femurOrientation * Vector3.left) * femurOrientation;
// Debug.DrawRay(femur.position, femurOrientation * Vector3.forward, Color.blue);
// Debug.DrawRay(femur.position, femurOrientation * Vector3.up, Color.green);
return femurOrientation;
}
protected Quaternion TibiaRotation(Vector3 targetPosition) {
if (this.tibiaTarget == null)
return Quaternion.identity;
Vector3 directionToTarget = targetPosition - this.tibiaTarget.position;
Quaternion tibiaOrientation = Quaternion.LookRotation(directionToTarget, Vector3.up); // femur.up);
return tibiaOrientation; // In world space
}
protected Quaternion TarsusRotation(Quaternion targetRotation) {
return targetRotation;
}
private void SetFemurOrientation(Transform bone, Quaternion orientation) {
if (this.femurTarget == null)
return;
// Debug.DrawRay(femur.position, orientation * Vector3.forward, Color.blue);
// Debug.DrawRay(femur.position, orientation * Vector3.up, Color.green);
bone.rotation = orientation;
}
private void SetTibiaOrientation(Transform bone, Quaternion orientation) {
if (this.tibiaTarget == null)
return;
bone.rotation = orientation;
}
private void SetTarsusOrientation(Transform bone, Quaternion orientation) {
if (this.tarsusTarget == null)
return;
bone.rotation = orientation;
}
// public void MatchToCreature(Transform femurBone, Transform tibiaBone, Transform tarsusBone) {
// TargetRig.MoveTargetToBone(femurTarget, femurBone);
// TargetRig.MoveTargetToBone(tibiaTarget, tibiaBone);
// TargetRig.MoveTargetToBone(tarsusTarget, tarsusBone);
// targetToBoneFemur = TargetRig.TargetToBoneRotation(femurBone, tibiaBone);
// targetToBoneTibia = TargetRig.TargetToBoneRotation(tibiaBone, tarsusBone);
// }
public void MatchToCreature(Leg leg) {
TargetRig.MoveTargetToBone(this.femurTarget, leg.femur);
TargetRig.MoveTargetToBone(this.tibiaTarget, leg.tibia);
TargetRig.MoveTargetToBone(this.tarsusTarget, leg.tarsus);
targetToBoneFemur = TargetRig.TargetToBoneRotation(leg.femur, leg.tibia);
targetToBoneTibia = TargetRig.TargetToBoneRotation(leg.tibia, leg.tarsus);
}
public void UpdateFemur(Transform femurBone) {
if (femurBone == null || this.femurTarget == null)
return;
femurBone.rotation = this.femurTarget.rotation * targetToBoneFemur;
}
public void UpdateTibia(Transform tibiaBone) {
if (tibiaBone == null || this.tibiaTarget == null)
return;
tibiaBone.rotation = this.tibiaTarget.rotation * targetToBoneTibia;
}
// public void UpdateBones(Transform femurBone, Transform tibiaBone) {
// UpdateFemur(femurBone);
// UpdateTibia(tibiaBone);
// }
public void UpdateBones(Leg leg) {
UpdateFemur(leg.femur);
UpdateTibia(leg.tibia);
}
#region Math
public static float CosineRule(float a, float b, float c) {
float a2 = a * a;
float b2 = b * b;
float c2 = c * c;
double angle = System.Math.Acos((a2 + b2 - c2) / (2 * a * b)) * Mathf.Rad2Deg;
if (double.IsNaN(angle))
angle = 0;
return (float)angle;
}
private static float Square(float x) {
return x * x;
}
#endregion Math
}
}

View File

@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: f3394e8da3685a263901c13e2a231279
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@ -0,0 +1,81 @@
using UnityEngine;
namespace Passer.CreatureControl {
// An insect target rig....
public class TargetRig : MonoBehaviour {
public TargetLeg leftFrontLeg;
public TargetLeg leftMiddleLeg;
public TargetLeg leftBackLeg;
public TargetLeg rightFrontLeg;
public TargetLeg rightMiddleLeg;
public TargetLeg rightBackLeg;
public Animator animator;
public void PoseLimbs() {
leftBackLeg.PoseLimb();
leftMiddleLeg.PoseLimb();
leftFrontLeg.PoseLimb();
rightBackLeg.PoseLimb();
rightMiddleLeg.PoseLimb();
rightFrontLeg.PoseLimb();
}
public void MatchTo(Insect insect) {
if (insect == null)
return;
if (leftFrontLeg != null && insect.leftFrontLeg != null)
leftFrontLeg.MatchToCreature(insect.leftFrontLeg);
if (leftMiddleLeg != null && insect.leftMiddleLeg != null)
leftMiddleLeg.MatchToCreature(insect.leftMiddleLeg);
if (leftBackLeg != null && insect.leftHindLeg != null)
leftBackLeg.MatchToCreature(insect.leftHindLeg);
if (rightFrontLeg != null && insect.rightFrontLeg != null)
rightFrontLeg.MatchToCreature(insect.rightFrontLeg);
if (rightMiddleLeg != null && insect.rightMiddleLeg != null)
rightMiddleLeg.MatchToCreature(insect.rightMiddleLeg);
if (rightBackLeg != null && insect.rightHindLeg != null)
rightBackLeg.MatchToCreature(insect.rightHindLeg);
}
public static void MoveTargetToBone(Transform target, Transform bone) {
if (target == null || bone == null)
return;
target.position = bone.position;
}
public static Quaternion TargetToBoneRotation(Transform bone, Transform nextBone) {
if (bone == null || nextBone == null)
return Quaternion.identity;
Vector3 direction = nextBone.position - bone.position;
Quaternion targetRotation = Quaternion.LookRotation(direction, Vector3.up);
Quaternion toBoneRotation = Quaternion.Inverse(targetRotation) * bone.rotation;
return toBoneRotation;
}
public static Quaternion TargetToBoneRotation(Transform target, Transform nextTarget, Transform bone) {
Vector3 direction = nextTarget.position - bone.position;
Quaternion targetRotation = Quaternion.LookRotation(direction, Vector3.up);
Quaternion toBoneRotation = Quaternion.Inverse(targetRotation) * bone.rotation;
return toBoneRotation;
}
public static Quaternion TargetToBoneRotation_Debug(Transform target, Transform nextTarget, Transform bone) {
Vector3 direction = nextTarget.position - target.position;
Quaternion targetRotation = Quaternion.LookRotation(direction, Vector3.up);
Debug.DrawRay(bone.position, targetRotation * Vector3.forward, Color.blue);
Debug.DrawRay(bone.position, targetRotation * Vector3.up, Color.green);
Quaternion toBoneRotation = Quaternion.Inverse(targetRotation) * bone.rotation;
Debug.Log($"{targetRotation.eulerAngles} {bone.rotation.eulerAngles} -> {toBoneRotation.eulerAngles}");
return toBoneRotation;
}
}
}

View File

@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: a25e8575da1d1cba48dc2b8da7a2b0ab
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@ -1,5 +1,5 @@
fileFormatVersion: 2
guid: 9d715489a5eda538a959b6e4cb89d1bc
guid: 1fa9ced5c1f8d9f45b173910d53bbe81
folderAsset: yes
DefaultImporter:
externalObjects: {}

8
Editor/Scripts.meta Normal file
View File

@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: 3a999e12de71fa28494cf28175deb1d5
folderAsset: yes
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

View File

@ -0,0 +1,22 @@
using UnityEditor;
namespace Passer.CreatureControl {
[CustomEditor(typeof(Ant))]
public class Ant_Editor : Insect_Editor {
protected Ant ant;
public override void OnEnable() {
base.OnEnable();
this.ant = target as Ant;
}
protected override void InitTargets(Creature creature) {
TargetsRigInspector(creature, "InsectTargetRig");
creature.targetRig.MatchTo(ant);
}
}
}

View File

@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 6d342503e4a28bac9aa53dca1bb602e2
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

8
NanoBrain.meta Normal file
View File

@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: c5f07463dfa08efc1bad0f3039a4cecc
folderAsset: yes
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

View File

@ -1,2 +1,11 @@
fileFormatVersion: 2
guid: f13cdc4a175a9f379a00317ae68d8bea
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@ -1,2 +1,11 @@
fileFormatVersion: 2
guid: 60a957541c24c57e78018c202ebb1d9b
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@ -1,2 +1,11 @@
fileFormatVersion: 2
guid: 4f64f5d72a422a7c8bb9ace598432aad
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@ -1,2 +1,11 @@
fileFormatVersion: 2
guid: 9197e2d322d23b5798ab4aef729815b0
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@ -1,2 +1,11 @@
fileFormatVersion: 2
guid: 1fc1fb7db9f7ad54a87d31313e7f457d
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@ -1,2 +1,11 @@
fileFormatVersion: 2
guid: 95393aed582b8b30d965400672aec4d8
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@ -1,2 +1,11 @@
fileFormatVersion: 2
guid: f05072314d39990639a2dbf99f322664
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@ -1,2 +1,11 @@
fileFormatVersion: 2
guid: 73f052292ad16bb53a3c07aa1694c705
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@ -1,4 +1,4 @@
//#if !UNITY_5_6_OR_NEWER
#if !UNITY_5_6_OR_NEWER
using System;
using System.Collections.Generic;
using NUnit.Framework;
@ -268,4 +268,4 @@ namespace LinearAlgebra.Test {
}
}
//#endif
#endif

View File

@ -1,2 +1,11 @@
fileFormatVersion: 2
guid: 29633aa3fe5cd9dcc8d886051f45d4d8
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@ -1,2 +1,11 @@
fileFormatVersion: 2
guid: 92f34a5e4027a1dc39efd8ce63cf6aba
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@ -2,8 +2,10 @@ using System;
using System.Collections.Generic;
using UnityEngine;
using UnityEditor;
#if UNITY_MATHEMATICS
using Unity.Mathematics;
using static Unity.Mathematics.math;
#endif
[Serializable]
public class Neuron : Nucleus {

View File

@ -1,2 +1,11 @@
fileFormatVersion: 2
guid: 750748f3f0e7d472fbf88ab02987074c
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@ -1,2 +1,11 @@
fileFormatVersion: 2
guid: 4310eea6ab77628b085387a226c1c386
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@ -1,2 +1,11 @@
fileFormatVersion: 2
guid: f8cac60bd79854595a8571c042f77998
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@ -1,2 +1,11 @@
fileFormatVersion: 2
guid: cfb9734aebc3ab85aacf87d26fb92e55
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@ -1,2 +1,11 @@
fileFormatVersion: 2
guid: 334a58eafccd60cbdb32f719e9e861c6
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

8
Runtime/Resources.meta Normal file
View File

@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: fd3f8dbf7199f6ffdaef4718aaaa4bb4
folderAsset: yes
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

View File

@ -0,0 +1,765 @@
%YAML 1.1
%TAG !u! tag:unity3d.com,2011:
--- !u!1 &217096157536176665
GameObject:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
serializedVersion: 6
m_Component:
- component: {fileID: 8557148899078362646}
m_Layer: 0
m_Name: RightHind_Tibia
m_TagString: Untagged
m_Icon: {fileID: 0}
m_NavMeshLayer: 0
m_StaticEditorFlags: 0
m_IsActive: 1
--- !u!4 &8557148899078362646
Transform:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 217096157536176665}
serializedVersion: 2
m_LocalRotation: {x: 0.74910194, y: 0.00000013411044, z: -0.000000059604638, w: 0.6624548}
m_LocalPosition: {x: -0.0000000060071543, y: 0.000000016929238, z: 0.017614825}
m_LocalScale: {x: 1, y: 1, z: 1}
m_ConstrainProportionsScale: 0
m_Children:
- {fileID: 2520372565419969361}
m_Father: {fileID: 7879963364189984297}
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
--- !u!1 &469742700386237715
GameObject:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
serializedVersion: 6
m_Component:
- component: {fileID: 2087731612450819825}
- component: {fileID: 4196034226083389076}
m_Layer: 0
m_Name: RightMiddle_Femur
m_TagString: Untagged
m_Icon: {fileID: 0}
m_NavMeshLayer: 0
m_StaticEditorFlags: 0
m_IsActive: 1
--- !u!4 &2087731612450819825
Transform:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 469742700386237715}
serializedVersion: 2
m_LocalRotation: {x: -0.30156508, y: 0.57948434, z: 0.24379016, w: 0.71681434}
m_LocalPosition: {x: 0.02, y: 0.04, z: -0.045}
m_LocalScale: {x: 3.4107811, y: 3.4107819, z: 3.4107828}
m_ConstrainProportionsScale: 0
m_Children:
- {fileID: 7566832081299524197}
m_Father: {fileID: 7044966310223004521}
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
--- !u!114 &4196034226083389076
MonoBehaviour:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 469742700386237715}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: f3394e8da3685a263901c13e2a231279, type: 3}
m_Name:
m_EditorClassIdentifier:
femurTarget: {fileID: 2087731612450819825}
tibiaTarget: {fileID: 7566832081299524197}
tarsusTarget: {fileID: 7011186323915432702}
target: {fileID: 0}
targetToBoneFemur: {x: 0, y: 0, z: 0, w: 0}
targetToBoneTibia: {x: 0, y: 0, z: 0, w: 0}
--- !u!1 &714113386832462525
GameObject:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
serializedVersion: 6
m_Component:
- component: {fileID: 7044966310223004521}
- component: {fileID: 5050182668285619700}
- component: {fileID: 5843436816833865534}
m_Layer: 0
m_Name: InsectTargetRig
m_TagString: Untagged
m_Icon: {fileID: 0}
m_NavMeshLayer: 0
m_StaticEditorFlags: 0
m_IsActive: 1
--- !u!4 &7044966310223004521
Transform:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 714113386832462525}
serializedVersion: 2
m_LocalRotation: {x: 0, y: 0, z: 0, w: 1}
m_LocalPosition: {x: 0, y: 0, z: 0}
m_LocalScale: {x: 1, y: 1, z: 1}
m_ConstrainProportionsScale: 0
m_Children:
- {fileID: 7827425323228862897}
- {fileID: 5158943779127512027}
- {fileID: 1138231466888029713}
- {fileID: 976560727556484423}
- {fileID: 2087731612450819825}
- {fileID: 7879963364189984297}
m_Father: {fileID: 0}
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
--- !u!114 &5050182668285619700
MonoBehaviour:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 714113386832462525}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: a25e8575da1d1cba48dc2b8da7a2b0ab, type: 3}
m_Name:
m_EditorClassIdentifier:
leftFrontLeg: {fileID: 5655676289343650514}
leftMiddleLeg: {fileID: 6327345715726789984}
leftBackLeg: {fileID: 3124099709297356894}
rightFrontLeg: {fileID: 5856460076900731150}
rightMiddleLeg: {fileID: 4196034226083389076}
rightBackLeg: {fileID: 8323677930838830493}
animator: {fileID: 5843436816833865534}
--- !u!95 &5843436816833865534
Animator:
serializedVersion: 5
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 714113386832462525}
m_Enabled: 1
m_Avatar: {fileID: 0}
m_Controller: {fileID: 9100000, guid: d4b9f32bef604abd5953647ad53ca0f7, type: 2}
m_CullingMode: 0
m_UpdateMode: 0
m_ApplyRootMotion: 1
m_LinearVelocityBlending: 0
m_StabilizeFeet: 0
m_WarningMessage:
m_HasTransformHierarchy: 1
m_AllowConstantClipSamplingOptimization: 1
m_KeepAnimatorStateOnDisable: 0
m_WriteDefaultValuesOnDisable: 0
--- !u!1 &816003872898039836
GameObject:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
serializedVersion: 6
m_Component:
- component: {fileID: 3473835942814004862}
m_Layer: 0
m_Name: LeftHind_Tarsus
m_TagString: Untagged
m_Icon: {fileID: 0}
m_NavMeshLayer: 0
m_StaticEditorFlags: 0
m_IsActive: 1
--- !u!4 &3473835942814004862
Transform:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 816003872898039836}
serializedVersion: 2
m_LocalRotation: {x: -0.3146679, y: 0.17643316, z: 0.007831901, w: -0.9326276}
m_LocalPosition: {x: 0.0000000016946835, y: -0.0000000055879354, z: 0.024077274}
m_LocalScale: {x: 0.9999999, y: 0.9999999, z: 0.9999999}
m_ConstrainProportionsScale: 0
m_Children: []
m_Father: {fileID: 6229249450306020558}
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
--- !u!1 &1193554740936415000
GameObject:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
serializedVersion: 6
m_Component:
- component: {fileID: 976560727556484423}
- component: {fileID: 5856460076900731150}
m_Layer: 0
m_Name: RightFront_Femur
m_TagString: Untagged
m_Icon: {fileID: 0}
m_NavMeshLayer: 0
m_StaticEditorFlags: 0
m_IsActive: 1
--- !u!4 &976560727556484423
Transform:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 1193554740936415000}
serializedVersion: 2
m_LocalRotation: {x: -0.17473988, y: 0.20808172, z: 0.03781085, w: 0.9616332}
m_LocalPosition: {x: 0.02, y: 0.04, z: -0.02}
m_LocalScale: {x: 3.4107826, y: 3.4107833, z: 3.410782}
m_ConstrainProportionsScale: 0
m_Children:
- {fileID: 3873135409852464941}
m_Father: {fileID: 7044966310223004521}
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
--- !u!114 &5856460076900731150
MonoBehaviour:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 1193554740936415000}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: f3394e8da3685a263901c13e2a231279, type: 3}
m_Name:
m_EditorClassIdentifier:
femurTarget: {fileID: 976560727556484423}
tibiaTarget: {fileID: 3873135409852464941}
tarsusTarget: {fileID: 3355004770557811387}
target: {fileID: 0}
targetToBoneFemur: {x: 0, y: 0, z: 0, w: 0}
targetToBoneTibia: {x: 0, y: 0, z: 0, w: 0}
--- !u!1 &1584550513300851516
GameObject:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
serializedVersion: 6
m_Component:
- component: {fileID: 7879963364189984297}
- component: {fileID: 8323677930838830493}
m_Layer: 0
m_Name: RightHind_Femur
m_TagString: Untagged
m_Icon: {fileID: 0}
m_NavMeshLayer: 0
m_StaticEditorFlags: 0
m_IsActive: 1
--- !u!4 &7879963364189984297
Transform:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 1584550513300851516}
serializedVersion: 2
m_LocalRotation: {x: -0.08576885, y: 0.91269386, z: 0.3088702, w: 0.25344208}
m_LocalPosition: {x: 0.02, y: 0.04, z: -0.06}
m_LocalScale: {x: 3.410783, y: 3.4107823, z: 3.4107835}
m_ConstrainProportionsScale: 0
m_Children:
- {fileID: 8557148899078362646}
m_Father: {fileID: 7044966310223004521}
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
--- !u!114 &8323677930838830493
MonoBehaviour:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 1584550513300851516}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: f3394e8da3685a263901c13e2a231279, type: 3}
m_Name:
m_EditorClassIdentifier:
femurTarget: {fileID: 7879963364189984297}
tibiaTarget: {fileID: 8557148899078362646}
tarsusTarget: {fileID: 2520372565419969361}
target: {fileID: 0}
targetToBoneFemur: {x: 0, y: 0, z: 0, w: 0}
targetToBoneTibia: {x: 0, y: 0, z: 0, w: 0}
--- !u!1 &1864955302254048131
GameObject:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
serializedVersion: 6
m_Component:
- component: {fileID: 5102382635668602733}
m_Layer: 0
m_Name: LeftMiddle_Tibia
m_TagString: Untagged
m_Icon: {fileID: 0}
m_NavMeshLayer: 0
m_StaticEditorFlags: 0
m_IsActive: 1
--- !u!4 &5102382635668602733
Transform:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 1864955302254048131}
serializedVersion: 2
m_LocalRotation: {x: 0.80736995, y: 0.0000005066394, z: -0.000000059604638, w: 0.59004563}
m_LocalPosition: {x: -0.000000010239469, y: 0.0000000013652621, z: 0.014121527}
m_LocalScale: {x: 0.9999998, y: 1, z: 1.0000001}
m_ConstrainProportionsScale: 0
m_Children:
- {fileID: 5832494694235077857}
m_Father: {fileID: 5158943779127512027}
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
--- !u!1 &1915398292779927248
GameObject:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
serializedVersion: 6
m_Component:
- component: {fileID: 2520372565419969361}
m_Layer: 0
m_Name: RightHind_Tarsus
m_TagString: Untagged
m_Icon: {fileID: 0}
m_NavMeshLayer: 0
m_StaticEditorFlags: 0
m_IsActive: 1
--- !u!4 &2520372565419969361
Transform:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 1915398292779927248}
serializedVersion: 2
m_LocalRotation: {x: -0.3146679, y: 0.17643316, z: 0.007831901, w: -0.9326276}
m_LocalPosition: {x: 0.0000000016946835, y: -0.0000000055879354, z: 0.024077274}
m_LocalScale: {x: 0.9999999, y: 0.9999999, z: 0.9999999}
m_ConstrainProportionsScale: 0
m_Children: []
m_Father: {fileID: 8557148899078362646}
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
--- !u!1 &3399675694450404938
GameObject:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
serializedVersion: 6
m_Component:
- component: {fileID: 5350519918537018444}
m_Layer: 0
m_Name: LeftFront_Tarsus
m_TagString: Untagged
m_Icon: {fileID: 0}
m_NavMeshLayer: 0
m_StaticEditorFlags: 0
m_IsActive: 1
--- !u!4 &5350519918537018444
Transform:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 3399675694450404938}
serializedVersion: 2
m_LocalRotation: {x: -0.08555651, y: 0.6380308, z: 0.42223927, w: 0.63820904}
m_LocalPosition: {x: -0.00000001637985, y: -0.0000000055879363, z: 0.017485214}
m_LocalScale: {x: 0.99999994, y: 0.99999994, z: 1}
m_ConstrainProportionsScale: 0
m_Children: []
m_Father: {fileID: 8607306932134183899}
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
--- !u!1 &3451781382000154612
GameObject:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
serializedVersion: 6
m_Component:
- component: {fileID: 5832494694235077857}
m_Layer: 0
m_Name: LeftMiddle_Tarsus
m_TagString: Untagged
m_Icon: {fileID: 0}
m_NavMeshLayer: 0
m_StaticEditorFlags: 0
m_IsActive: 1
--- !u!4 &5832494694235077857
Transform:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 3451781382000154612}
serializedVersion: 2
m_LocalRotation: {x: -0.44156942, y: -0.45806083, z: -0.5668181, w: -0.5233678}
m_LocalPosition: {x: 0.000000013656518, y: 0, z: 0.024214728}
m_LocalScale: {x: 1, y: 1, z: 1}
m_ConstrainProportionsScale: 0
m_Children: []
m_Father: {fileID: 5102382635668602733}
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
--- !u!1 &4305921432289450317
GameObject:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
serializedVersion: 6
m_Component:
- component: {fileID: 3355004770557811387}
m_Layer: 0
m_Name: RightFront_Tarsus
m_TagString: Untagged
m_Icon: {fileID: 0}
m_NavMeshLayer: 0
m_StaticEditorFlags: 0
m_IsActive: 1
--- !u!4 &3355004770557811387
Transform:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 4305921432289450317}
serializedVersion: 2
m_LocalRotation: {x: -0.08555651, y: 0.6380308, z: 0.42223927, w: 0.63820904}
m_LocalPosition: {x: -0.00000001637985, y: -0.0000000055879363, z: 0.017485214}
m_LocalScale: {x: 0.99999994, y: 0.99999994, z: 1}
m_ConstrainProportionsScale: 0
m_Children: []
m_Father: {fileID: 3873135409852464941}
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
--- !u!1 &5930454242050132924
GameObject:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
serializedVersion: 6
m_Component:
- component: {fileID: 1138231466888029713}
- component: {fileID: 3124099709297356894}
m_Layer: 0
m_Name: LeftHind_Femur
m_TagString: Untagged
m_Icon: {fileID: 0}
m_NavMeshLayer: 0
m_StaticEditorFlags: 0
m_IsActive: 1
--- !u!4 &1138231466888029713
Transform:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 5930454242050132924}
serializedVersion: 2
m_LocalRotation: {x: 0.08395476, y: 0.91604495, z: 0.27771258, w: -0.27692783}
m_LocalPosition: {x: -0.02, y: 0.04, z: -0.06}
m_LocalScale: {x: 3.4107823, y: 3.4107852, z: 3.410783}
m_ConstrainProportionsScale: 0
m_Children:
- {fileID: 6229249450306020558}
m_Father: {fileID: 7044966310223004521}
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
--- !u!114 &3124099709297356894
MonoBehaviour:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 5930454242050132924}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: f3394e8da3685a263901c13e2a231279, type: 3}
m_Name:
m_EditorClassIdentifier:
femurTarget: {fileID: 1138231466888029713}
tibiaTarget: {fileID: 6229249450306020558}
tarsusTarget: {fileID: 3473835942814004862}
target: {fileID: 0}
targetToBoneFemur: {x: 0, y: 0, z: 0, w: 0}
targetToBoneTibia: {x: 0, y: 0, z: 0, w: 0}
--- !u!1 &6227205784071755847
GameObject:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
serializedVersion: 6
m_Component:
- component: {fileID: 8607306932134183899}
m_Layer: 0
m_Name: LeftFront_Tibia
m_TagString: Untagged
m_Icon: {fileID: 0}
m_NavMeshLayer: 0
m_StaticEditorFlags: 0
m_IsActive: 1
--- !u!4 &8607306932134183899
Transform:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 6227205784071755847}
serializedVersion: 2
m_LocalRotation: {x: 0.65185237, y: -0.00000028312206, z: 0.000000113621354, w: 0.7583459}
m_LocalPosition: {x: 0.000000004914944, y: -0.0000000049149436, z: 0.011160721}
m_LocalScale: {x: 1, y: 0.9999999, z: 0.99999994}
m_ConstrainProportionsScale: 0
m_Children:
- {fileID: 5350519918537018444}
m_Father: {fileID: 7827425323228862897}
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
--- !u!1 &6521710740082976927
GameObject:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
serializedVersion: 6
m_Component:
- component: {fileID: 3873135409852464941}
m_Layer: 0
m_Name: RightFront_Tibia
m_TagString: Untagged
m_Icon: {fileID: 0}
m_NavMeshLayer: 0
m_StaticEditorFlags: 0
m_IsActive: 1
--- !u!4 &3873135409852464941
Transform:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 6521710740082976927}
serializedVersion: 2
m_LocalRotation: {x: 0.65185237, y: -0.00000028312206, z: 0.000000113621354, w: 0.7583459}
m_LocalPosition: {x: 0.000000004914944, y: -0.0000000049149436, z: 0.011160721}
m_LocalScale: {x: 1, y: 0.9999999, z: 0.99999994}
m_ConstrainProportionsScale: 0
m_Children:
- {fileID: 3355004770557811387}
m_Father: {fileID: 976560727556484423}
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
--- !u!1 &6621691774974300190
GameObject:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
serializedVersion: 6
m_Component:
- component: {fileID: 5158943779127512027}
- component: {fileID: 6327345715726789984}
m_Layer: 0
m_Name: LeftMiddle_Femur
m_TagString: Untagged
m_Icon: {fileID: 0}
m_NavMeshLayer: 0
m_StaticEditorFlags: 0
m_IsActive: 1
--- !u!4 &5158943779127512027
Transform:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 6621691774974300190}
serializedVersion: 2
m_LocalRotation: {x: -0.29419467, y: -0.5819551, z: -0.23783171, w: 0.7198708}
m_LocalPosition: {x: -0.02, y: 0.04, z: -0.045}
m_LocalScale: {x: 3.410782, y: 3.410783, z: 3.4107823}
m_ConstrainProportionsScale: 0
m_Children:
- {fileID: 5102382635668602733}
m_Father: {fileID: 7044966310223004521}
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
--- !u!114 &6327345715726789984
MonoBehaviour:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 6621691774974300190}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: f3394e8da3685a263901c13e2a231279, type: 3}
m_Name:
m_EditorClassIdentifier:
femurTarget: {fileID: 5158943779127512027}
tibiaTarget: {fileID: 5102382635668602733}
tarsusTarget: {fileID: 5832494694235077857}
target: {fileID: 0}
targetToBoneFemur: {x: 0, y: 0, z: 0, w: 0}
targetToBoneTibia: {x: 0, y: 0, z: 0, w: 0}
--- !u!1 &6934656281848074513
GameObject:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
serializedVersion: 6
m_Component:
- component: {fileID: 7011186323915432702}
m_Layer: 0
m_Name: RightMiddle_Tarsus
m_TagString: Untagged
m_Icon: {fileID: 0}
m_NavMeshLayer: 0
m_StaticEditorFlags: 0
m_IsActive: 1
--- !u!4 &7011186323915432702
Transform:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 6934656281848074513}
serializedVersion: 2
m_LocalRotation: {x: -0.44156942, y: -0.45806083, z: -0.5668181, w: -0.5233678}
m_LocalPosition: {x: 0.000000013656518, y: 0, z: 0.024214728}
m_LocalScale: {x: 1, y: 1, z: 1}
m_ConstrainProportionsScale: 0
m_Children: []
m_Father: {fileID: 7566832081299524197}
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
--- !u!1 &8313487703600456217
GameObject:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
serializedVersion: 6
m_Component:
- component: {fileID: 7566832081299524197}
m_Layer: 0
m_Name: RightMiddle_Tibia
m_TagString: Untagged
m_Icon: {fileID: 0}
m_NavMeshLayer: 0
m_StaticEditorFlags: 0
m_IsActive: 1
--- !u!4 &7566832081299524197
Transform:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 8313487703600456217}
serializedVersion: 2
m_LocalRotation: {x: 0.80736995, y: 0.0000005066394, z: -0.000000059604638, w: 0.59004563}
m_LocalPosition: {x: -0.000000010239469, y: 0.0000000013652621, z: 0.014121527}
m_LocalScale: {x: 0.9999998, y: 1, z: 1.0000001}
m_ConstrainProportionsScale: 0
m_Children:
- {fileID: 7011186323915432702}
m_Father: {fileID: 2087731612450819825}
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
--- !u!1 &8534431202702769095
GameObject:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
serializedVersion: 6
m_Component:
- component: {fileID: 6229249450306020558}
m_Layer: 0
m_Name: LeftHind_Tibia
m_TagString: Untagged
m_Icon: {fileID: 0}
m_NavMeshLayer: 0
m_StaticEditorFlags: 0
m_IsActive: 1
--- !u!4 &6229249450306020558
Transform:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 8534431202702769095}
serializedVersion: 2
m_LocalRotation: {x: 0.74910194, y: 0.00000013411044, z: -0.000000059604638, w: 0.6624548}
m_LocalPosition: {x: -0.0000000060071543, y: 0.000000016929238, z: 0.017614825}
m_LocalScale: {x: 1, y: 1, z: 1}
m_ConstrainProportionsScale: 0
m_Children:
- {fileID: 3473835942814004862}
m_Father: {fileID: 1138231466888029713}
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
--- !u!1 &9008164333968854526
GameObject:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
serializedVersion: 6
m_Component:
- component: {fileID: 7827425323228862897}
- component: {fileID: 5655676289343650514}
m_Layer: 0
m_Name: LeftFront_Femur
m_TagString: Untagged
m_Icon: {fileID: 0}
m_NavMeshLayer: 0
m_StaticEditorFlags: 0
m_IsActive: 1
--- !u!4 &7827425323228862897
Transform:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 9008164333968854526}
serializedVersion: 2
m_LocalRotation: {x: -0.16464043, y: -0.208467, z: -0.035625506, w: 0.96341366}
m_LocalPosition: {x: -0.02, y: 0.04, z: -0.02}
m_LocalScale: {x: 3.4107828, y: 3.410783, z: 3.4107833}
m_ConstrainProportionsScale: 0
m_Children:
- {fileID: 8607306932134183899}
m_Father: {fileID: 7044966310223004521}
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
--- !u!114 &5655676289343650514
MonoBehaviour:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 9008164333968854526}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: f3394e8da3685a263901c13e2a231279, type: 3}
m_Name:
m_EditorClassIdentifier:
femurTarget: {fileID: 7827425323228862897}
tibiaTarget: {fileID: 8607306932134183899}
tarsusTarget: {fileID: 5350519918537018444}
target: {fileID: 0}
targetToBoneFemur: {x: 0, y: 0, z: 0, w: 0}
targetToBoneTibia: {x: 0, y: 0, z: 0, w: 0}

View File

@ -0,0 +1,7 @@
fileFormatVersion: 2
guid: 587ec75114263dfb3870e4c140f45f79
PrefabImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

View File

@ -1,245 +0,0 @@
using System.Collections.Generic;
using UnityEngine;
[RequireComponent(typeof(NanoBrain))]
public class AnimatedAnt : MonoBehaviour {
private readonly float inertia = 0.2f;
private readonly float smellRadius = 1.0f;
private readonly float smellAngle = 80.0f;
public GameObject homePheromonePrefab;
public GameObject foodPheromonePrefab;
public AntennaTouch touchLeft;
public AntennaTouch touchRight;
public NanoBrain nanoBrain;
// brain output
public Neuron hasFood;
// brain input
public Nucleus pheromoneSteering;
public Nucleus hitLeft;
public Nucleus hitRight;
public Nucleus beat;
public Receptor foodReceptor;
public Receptor homeReceptor;
public new Rigidbody rigidbody;
public Animator animator;
public float forwardSpeed = 1;
public float rotationSpeed = 1;
public Vector3 linearVelocity;
public Vector3 angularVelocity;
protected virtual void Awake() {
this.animator = GetComponentInChildren<Animator>();
if (this.animator == null && this.transform.parent != null)
this.animator = this.transform.parent.GetComponentInChildren<Animator>();
this.nanoBrain = GetComponentInChildren<NanoBrain>();
this.rigidbody = GetComponentInParent<Rigidbody>();
this.rigidbody.isKinematic = false;
}
void Start() {
Cluster brain = this.nanoBrain.brain;
if (brain != null) {
// brain outputs
this.pheromoneSteering = brain.GetNucleus("Pheromone Steering");
if (brain.GetNucleus("Home Pheromones") is Neuron homePheromones)
homePheromones.WhenFiring += PlaceHomePheromone;
if (brain.GetNucleus("Food Pheromones") is Neuron foodPheromones)
foodPheromones.WhenFiring += PlaceFoodPheromone;
this.hasFood = brain.GetNucleus("Having Food") as Neuron;
// brain inputs
this.beat = brain.GetNucleus("Beat");
this.hitLeft = brain.GetNucleus("Hit Left");
this.hitRight = brain.GetNucleus("Hit Right");
this.foodReceptor = brain.GetNucleus("Food Receptor") as Receptor;
this.homeReceptor = brain.GetNucleus("Home Receptor") as Receptor;
}
this.linearVelocity = Vector3.forward;
if (touchLeft != null)
touchLeft.touched += OnAntennaTouchLeft;
if (touchRight != null)
touchRight.touched += OnAntennaTouchRight;
}
void PlaceFoodPheromone() {
GameObject pheromoneObj = Instantiate(foodPheromonePrefab);
pheromoneObj.transform.position = this.transform.position;
}
void PlaceHomePheromone() {
GameObject pheromoneObj = Instantiate(homePheromonePrefab);
pheromoneObj.transform.position = this.transform.position;
}
// Update is called once per frame
void Update() {
UpdateBeat();
UpdateSmell();
if (this.nanoBrain == null || this.nanoBrain.brain == null || this.animator == null)
return;
Vector3 localForce = nanoBrain.brain.defaultOutput.outputValue;
this.linearVelocity = (1 - inertia) * (Time.deltaTime * localForce.normalized) + inertia * this.linearVelocity;
this.linearVelocity = this.linearVelocity.normalized * 0.2f;
// Vector3 linearVelocityWorld = this.transform.TransformVector(this.linearVelocity);
// this.rigidbody.linearVelocity = linearVelocityWorld;
this.animator.SetFloat("forward speed", this.linearVelocity.z * this.forwardSpeed);
// Rotate towards the movement direction
if (this.linearVelocity != Vector3.zero) {
Quaternion targetRotation = Quaternion.LookRotation(this.linearVelocity);
Quaternion worldRotation = transform.rotation * targetRotation;
Quaternion deltaRotation = worldRotation * Quaternion.Inverse(transform.rotation);
Vector3 eulerAngleChange = deltaRotation.eulerAngles;
// Normalize the Euler angles to avoid unexpected jumps due to 360-degree rotations
eulerAngleChange = new Vector3(
LinearAlgebra.Angles.Normalize(eulerAngleChange.x),
LinearAlgebra.Angles.Normalize(eulerAngleChange.y),
LinearAlgebra.Angles.Normalize(eulerAngleChange.z)
);
Vector3 angularVelocity = 5f * Mathf.Deg2Rad * eulerAngleChange;
//rigidbody.angularVelocity = angularVelocity;
this.animator.SetFloat("rotate speed", eulerAngleChange.y / 45 * this.rotationSpeed);
}
}
public float beatInterval = 3;
float lastBeatTime = 0;
void UpdateBeat() {
if (lastBeatTime == 0) {
ulong delay = (ulong)(UnityEngine.Random.value * beatInterval);
lastBeatTime = Time.time - delay;
}
if (Time.time - lastBeatTime >= beatInterval) {
lastBeatTime = Time.time;
beat?.SetBias(Vector3.one); //, 0);
}
}
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) {
SmellPheromones(collider);
SmellFood(collider);
SmellHome(collider);
}
if (nanoBrain != null && nanoBrain.brain != null)
nanoBrain.brain.UpdateNuclei();
}
void SmellPheromones(Collider thing) {
Pheromone pheromone = thing.GetComponentInParent<Pheromone>();
if (pheromone == null)
return;
// if (hasFood == null)
// return;
// if ((hasFood.outputValue.x > 0 && pheromone.type == Pheromone.Type.Home) ||
// (hasFood.outputValue.x < 0 && pheromone.type == Pheromone.Type.Food)) {
// Vector3 smellDirection = this.transform.InverseTransformPoint(pheromone.transform.position);
// float distance = smellDirection.magnitude;
// float angle = Vector3.Angle(Vector3.forward, smellDirection);
// if (angle < smellAngle && smellDirection.magnitude > 0.05) {
// float intensity = pheromone.StrengthAt(distance);//strength * (1 / distance);
// pheromoneSteering?.ProcessStimulus(pheromone.GetInstanceID(), smellDirection.normalized * intensity,
// pheromone.type.ToString() + " pheromone");
// //Debug.DrawLine(this.transform.position, pheromone.transform.position, Color.magenta);
// }
// }
Vector3 smellDirection = this.transform.InverseTransformPoint(pheromone.transform.position);
float distance = smellDirection.magnitude;
float angle = Vector3.Angle(Vector3.forward, smellDirection);
if (angle < smellAngle && smellDirection.magnitude > 0.05) {
float intensity = pheromone.StrengthAt(distance);
Vector3 smell = smellDirection.normalized * intensity;
switch (pheromone.type) {
case Pheromone.Type.Food:
//foodSmell?.ProcessStimulus(pheromone.GetInstanceID(), smell, "food pheromone");
foodReceptor?.ProcessStimulus(smellDirection.normalized * intensity, pheromone.GetInstanceID(), "food pheromone");
break;
case Pheromone.Type.Home:
//pheromoneSteering?.ProcessStimulus(pheromone.GetInstanceID(), smell, "home pheromone");
//homeSmell?.ProcessStimulus(pheromone.GetInstanceID(), smell, "home pheromone");
homeReceptor?.ProcessStimulus(smellDirection.normalized * intensity, pheromone.GetInstanceID(), "home pheromone");
break;
}
//Debug.DrawLine(this.transform.position, pheromone.transform.position, Color.magenta);
}
}
void SmellFood(Collider thing) {
if (hasFood != null && hasFood.outputValue.x > 0)
// if it has food...
return;
Food food = thing.GetComponentInParent<Food>();
if (food == null)
return;
Vector3 smellDirection = this.transform.InverseTransformPoint(food.transform.position);
float distance = smellDirection.magnitude;
float angle = Vector3.Angle(Vector3.forward, smellDirection);
if (angle < smellAngle && distance > 0.05) {
float intensity = food.StrengthAt(distance); //strength * (1 / distance);
//foodSmell?.ProcessStimulus(food.GetInstanceID(), smellDirection.normalized * intensity, "food");
foodReceptor?.ProcessStimulus(smellDirection.normalized * intensity, food.GetInstanceID(), "food");
Debug.DrawLine(this.transform.position, food.transform.position, Color.red);
}
}
void SmellHome(Collider thing) {
if (hasFood != null && hasFood.outputValue.x < 0)
// if it does not have food....
return;
AntsNest nest = thing.GetComponentInParent<AntsNest>();
if (nest == null)
return;
Vector3 smellDirection = this.transform.InverseTransformPoint(nest.transform.position);
float distance = smellDirection.magnitude;
float angle = Vector3.Angle(Vector3.forward, smellDirection);
if (angle < smellAngle && distance > 0.05) {
float intensity = nest.StrengthAt(distance); //strength * (1 / distance);
//homeSmell?.ProcessStimulus(nest.GetInstanceID(), smellDirection.normalized * intensity, "nest");
Vector3 value = smellDirection.normalized * intensity;
homeReceptor?.ProcessStimulus(value, nest.GetInstanceID(), "nest");
Debug.DrawLine(this.transform.position, nest.transform.position, Color.red);
}
}
void OnAntennaTouchLeft(Collider other, bool isTouching) {
Vector3 touchDirection = Vector3.zero;
if (isTouching)
touchDirection = this.transform.InverseTransformVector(touchLeft.transform.forward);
hitLeft?.SetBias(touchDirection); //, other.GetInstanceID(), "Touch Left");
}
void OnAntennaTouchRight(Collider other, bool isTouching) {
Vector3 touchDirection = Vector3.zero;
if (isTouching)
touchDirection = this.transform.InverseTransformVector(touchRight.transform.forward);
hitRight?.SetBias(touchDirection); //, other.GetInstanceID(), "Touch Right");
}
}

249
Runtime/Scripts/Ant.cs Normal file
View File

@ -0,0 +1,249 @@
using System.Collections.Generic;
using UnityEngine;
namespace Passer.CreatureControl {
[RequireComponent(typeof(NanoBrain))]
public class Ant : Insect {
private readonly float inertia = 0.2f;
private readonly float smellRadius = 1.0f;
private readonly float smellAngle = 80.0f;
public GameObject homePheromonePrefab;
public GameObject foodPheromonePrefab;
public AntennaTouch touchLeft;
public AntennaTouch touchRight;
public NanoBrain nanoBrain;
// brain output
public Neuron hasFood;
// brain input
public Nucleus pheromoneSteering;
public Nucleus hitLeft;
public Nucleus hitRight;
public Nucleus beat;
public Receptor foodReceptor;
public Receptor homeReceptor;
public new Rigidbody rigidbody;
public Animator animator;
public float forwardSpeed = 1;
public float rotationSpeed = 1;
public Vector3 linearVelocity;
public Vector3 angularVelocity;
protected virtual void Awake() {
this.animator = GetComponentInChildren<Animator>();
if (this.animator == null && this.transform.parent != null)
this.animator = this.transform.parent.GetComponentInChildren<Animator>();
this.nanoBrain = GetComponentInChildren<NanoBrain>();
this.rigidbody = GetComponentInParent<Rigidbody>();
this.rigidbody.isKinematic = false;
}
void Start() {
Cluster brain = this.nanoBrain.brain;
if (brain != null) {
// brain outputs
this.pheromoneSteering = brain.GetNucleus("Pheromone Steering");
if (brain.GetNucleus("Home Pheromones") is Neuron homePheromones)
homePheromones.WhenFiring += PlaceHomePheromone;
if (brain.GetNucleus("Food Pheromones") is Neuron foodPheromones)
foodPheromones.WhenFiring += PlaceFoodPheromone;
this.hasFood = brain.GetNucleus("Having Food") as Neuron;
// brain inputs
this.beat = brain.GetNucleus("Beat");
this.hitLeft = brain.GetNucleus("Hit Left");
this.hitRight = brain.GetNucleus("Hit Right");
this.foodReceptor = brain.GetNucleus("Food Receptor") as Receptor;
this.homeReceptor = brain.GetNucleus("Home Receptor") as Receptor;
}
this.linearVelocity = Vector3.forward;
if (touchLeft != null)
touchLeft.touched += OnAntennaTouchLeft;
if (touchRight != null)
touchRight.touched += OnAntennaTouchRight;
}
void PlaceFoodPheromone() {
GameObject pheromoneObj = Instantiate(foodPheromonePrefab);
pheromoneObj.transform.position = this.transform.position;
}
void PlaceHomePheromone() {
GameObject pheromoneObj = Instantiate(homePheromonePrefab);
pheromoneObj.transform.position = this.transform.position;
}
// Update is called once per frame
void Update() {
UpdateBeat();
UpdateSmell();
if (this.nanoBrain == null || this.nanoBrain.brain == null || this.animator == null)
return;
Vector3 localForce = nanoBrain.brain.defaultOutput.outputValue;
this.linearVelocity = (1 - inertia) * (Time.deltaTime * localForce.normalized) + inertia * this.linearVelocity;
this.linearVelocity = this.linearVelocity.normalized * 0.2f;
// Vector3 linearVelocityWorld = this.transform.TransformVector(this.linearVelocity);
// this.rigidbody.linearVelocity = linearVelocityWorld;
this.animator.SetFloat("forward speed", this.linearVelocity.z * this.forwardSpeed);
// Rotate towards the movement direction
if (this.linearVelocity != Vector3.zero) {
Quaternion targetRotation = Quaternion.LookRotation(this.linearVelocity);
Quaternion worldRotation = transform.rotation * targetRotation;
Quaternion deltaRotation = worldRotation * Quaternion.Inverse(transform.rotation);
Vector3 eulerAngleChange = deltaRotation.eulerAngles;
// Normalize the Euler angles to avoid unexpected jumps due to 360-degree rotations
eulerAngleChange = new Vector3(
LinearAlgebra.Angles.Normalize(eulerAngleChange.x),
LinearAlgebra.Angles.Normalize(eulerAngleChange.y),
LinearAlgebra.Angles.Normalize(eulerAngleChange.z)
);
Vector3 angularVelocity = 5f * Mathf.Deg2Rad * eulerAngleChange;
//rigidbody.angularVelocity = angularVelocity;
this.animator.SetFloat("rotate speed", eulerAngleChange.y / 45 * this.rotationSpeed);
}
}
public float beatInterval = 3;
float lastBeatTime = 0;
void UpdateBeat() {
if (lastBeatTime == 0) {
ulong delay = (ulong)(UnityEngine.Random.value * beatInterval);
lastBeatTime = Time.time - delay;
}
if (Time.time - lastBeatTime >= beatInterval) {
lastBeatTime = Time.time;
beat?.SetBias(Vector3.one); //, 0);
}
}
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) {
SmellPheromones(collider);
SmellFood(collider);
SmellHome(collider);
}
if (nanoBrain != null && nanoBrain.brain != null)
nanoBrain.brain.UpdateNuclei();
}
void SmellPheromones(Collider thing) {
Pheromone pheromone = thing.GetComponentInParent<Pheromone>();
if (pheromone == null)
return;
// if (hasFood == null)
// return;
// if ((hasFood.outputValue.x > 0 && pheromone.type == Pheromone.Type.Home) ||
// (hasFood.outputValue.x < 0 && pheromone.type == Pheromone.Type.Food)) {
// Vector3 smellDirection = this.transform.InverseTransformPoint(pheromone.transform.position);
// float distance = smellDirection.magnitude;
// float angle = Vector3.Angle(Vector3.forward, smellDirection);
// if (angle < smellAngle && smellDirection.magnitude > 0.05) {
// float intensity = pheromone.StrengthAt(distance);//strength * (1 / distance);
// pheromoneSteering?.ProcessStimulus(pheromone.GetInstanceID(), smellDirection.normalized * intensity,
// pheromone.type.ToString() + " pheromone");
// //Debug.DrawLine(this.transform.position, pheromone.transform.position, Color.magenta);
// }
// }
Vector3 smellDirection = this.transform.InverseTransformPoint(pheromone.transform.position);
float distance = smellDirection.magnitude;
float angle = Vector3.Angle(Vector3.forward, smellDirection);
if (angle < smellAngle && smellDirection.magnitude > 0.05) {
float intensity = pheromone.StrengthAt(distance);
Vector3 smell = smellDirection.normalized * intensity;
switch (pheromone.type) {
case Pheromone.Type.Food:
//foodSmell?.ProcessStimulus(pheromone.GetInstanceID(), smell, "food pheromone");
foodReceptor?.ProcessStimulus(smellDirection.normalized * intensity, pheromone.GetInstanceID(), "food pheromone");
break;
case Pheromone.Type.Home:
//pheromoneSteering?.ProcessStimulus(pheromone.GetInstanceID(), smell, "home pheromone");
//homeSmell?.ProcessStimulus(pheromone.GetInstanceID(), smell, "home pheromone");
homeReceptor?.ProcessStimulus(smellDirection.normalized * intensity, pheromone.GetInstanceID(), "home pheromone");
break;
}
//Debug.DrawLine(this.transform.position, pheromone.transform.position, Color.magenta);
}
}
void SmellFood(Collider thing) {
if (hasFood != null && hasFood.outputValue.x > 0)
// if it has food...
return;
Food food = thing.GetComponentInParent<Food>();
if (food == null)
return;
Vector3 smellDirection = this.transform.InverseTransformPoint(food.transform.position);
float distance = smellDirection.magnitude;
float angle = Vector3.Angle(Vector3.forward, smellDirection);
if (angle < smellAngle && distance > 0.05) {
float intensity = food.StrengthAt(distance); //strength * (1 / distance);
//foodSmell?.ProcessStimulus(food.GetInstanceID(), smellDirection.normalized * intensity, "food");
foodReceptor?.ProcessStimulus(smellDirection.normalized * intensity, food.GetInstanceID(), "food");
Debug.DrawLine(this.transform.position, food.transform.position, Color.red);
}
}
void SmellHome(Collider thing) {
if (hasFood != null && hasFood.outputValue.x < 0)
// if it does not have food....
return;
AntsNest nest = thing.GetComponentInParent<AntsNest>();
if (nest == null)
return;
Vector3 smellDirection = this.transform.InverseTransformPoint(nest.transform.position);
float distance = smellDirection.magnitude;
float angle = Vector3.Angle(Vector3.forward, smellDirection);
if (angle < smellAngle && distance > 0.05) {
float intensity = nest.StrengthAt(distance); //strength * (1 / distance);
//homeSmell?.ProcessStimulus(nest.GetInstanceID(), smellDirection.normalized * intensity, "nest");
Vector3 value = smellDirection.normalized * intensity;
homeReceptor?.ProcessStimulus(value, nest.GetInstanceID(), "nest");
Debug.DrawLine(this.transform.position, nest.transform.position, Color.red);
}
}
void OnAntennaTouchLeft(Collider other, bool isTouching) {
Vector3 touchDirection = Vector3.zero;
if (isTouching)
touchDirection = this.transform.InverseTransformVector(touchLeft.transform.forward);
hitLeft?.SetBias(touchDirection); //, other.GetInstanceID(), "Touch Left");
}
void OnAntennaTouchRight(Collider other, bool isTouching) {
Vector3 touchDirection = Vector3.zero;
if (isTouching)
touchDirection = this.transform.InverseTransformVector(touchRight.transform.forward);
hitRight?.SetBias(touchDirection); //, other.GetInstanceID(), "Touch Right");
}
}
}

View File

@ -1,32 +1,36 @@
using System.Collections;
using UnityEngine;
public class AntsNest : Odorant {
namespace Passer.CreatureControl {
public Ant antPrefab;
public uint numberOfAnts = 1;
public bool spawnAnt = false;
public class AntsNest : Odorant {
private uint antCount = 0;
protected virtual void Start() {
StartCoroutine(SpawnAnts());
}
IEnumerator SpawnAnts() {
while (numberOfAnts > 0) {
Ant ant = Instantiate(antPrefab);
ant.transform.eulerAngles = 360 * Random.value * Vector3.up;
ant.transform.position = this.transform.position + ant.transform.forward * 0.1F;
ant.name = "Ant " + (++antCount);
numberOfAnts--;
yield return new WaitForSeconds(0.2f);
public Ant antPrefab;
public uint numberOfAnts = 1;
public bool spawnAnt = false;
private uint antCount = 0;
protected virtual void Start() {
StartCoroutine(SpawnAnts());
}
IEnumerator SpawnAnts() {
while (numberOfAnts > 0) {
Ant ant = Instantiate(antPrefab);
ant.transform.eulerAngles = 360 * Random.value * Vector3.up;
ant.transform.position = this.transform.position + ant.transform.forward * 0.1F;
ant.name = "Ant " + (++antCount);
numberOfAnts--;
yield return new WaitForSeconds(0.2f);
}
}
protected virtual void Update() {
if (spawnAnt) {
Ant ant = Instantiate(antPrefab);
ant.name = "Ant " + (++antCount);
spawnAnt = false;
}
}
}
protected virtual void Update() {
if (spawnAnt) {
Ant ant = Instantiate(antPrefab);
ant.name = "Ant " + (++antCount);
spawnAnt = false;
}
}
}

View File

@ -1,64 +1,68 @@
using System.Collections.Generic;
using UnityEngine;
public class Mouth : MonoBehaviour {
public GameObject foodPrefab;
public NanoBrain nanoBrain;
namespace Passer.CreatureControl {
public Neuron havingFood;
public Nucleus enableFoodPheromones;
public class Mouth : MonoBehaviour {
public GameObject foodPrefab;
public NanoBrain nanoBrain;
void Awake() {
this.nanoBrain = GetComponentInParent<NanoBrain>();
if (this.nanoBrain == null || this.nanoBrain.brain == null)
return;
public Neuron havingFood;
public Nucleus enableFoodPheromones;
if (nanoBrain.brain.GetNucleus("Mouth") is Neuron mouthNeuron)
mouthNeuron.WhenFiring += CheckGrab;
this.havingFood = nanoBrain.brain.GetNucleus("Having Food") as Neuron;
}
void Awake() {
this.nanoBrain = GetComponentInParent<NanoBrain>();
if (this.nanoBrain == null || this.nanoBrain.brain == null)
return;
void Start() {
havingFood?.SetBias(-Vector3.one);
}
if (nanoBrain.brain.GetNucleus("Mouth") is Neuron mouthNeuron)
mouthNeuron.WhenFiring += CheckGrab;
this.havingFood = nanoBrain.brain.GetNucleus("Having Food") as Neuron;
}
protected void CheckGrab() {
if (havingFood == null)
return;
Collider[] colliders = Physics.OverlapSphere(this.transform.position, 0.04f);
foreach (Collider c in colliders) {
if (havingFood.outputValue.x > 0) {
AntsNest nest = c.GetComponentInParent<AntsNest>();
if (nest != null)
LetGo();
}
else {
Food food = c.GetComponentInParent<Food>();
if (food != null)
Grab();
void Start() {
havingFood?.SetBias(-Vector3.one);
}
protected void CheckGrab() {
if (havingFood == null)
return;
Collider[] colliders = Physics.OverlapSphere(this.transform.position, 0.04f);
foreach (Collider c in colliders) {
if (havingFood.outputValue.x > 0) {
AntsNest nest = c.GetComponentInParent<AntsNest>();
if (nest != null)
LetGo();
}
else {
Food food = c.GetComponentInParent<Food>();
if (food != null)
Grab();
}
}
}
public bool Grab() {
//Debug.Log($"{this.transform.parent.name} Grab food");
havingFood?.SetBias(Vector3.one);
GameObject food = Instantiate(foodPrefab);
food.transform.SetParent(this.transform, false);
food.transform.localPosition = Vector3.zero;
return true;
}
public void LetGo() {
//Debug.Log($"{this.transform.parent.name} Release food");
List<GameObject> toDelete = new();
for (int i = 0; i < transform.childCount; i++)
toDelete.Add(transform.GetChild(i).gameObject);
foreach (GameObject go in toDelete)
Destroy(go);
havingFood?.SetBias(-Vector3.one);
}
}
public bool Grab() {
//Debug.Log($"{this.transform.parent.name} Grab food");
havingFood?.SetBias(Vector3.one);
GameObject food = Instantiate(foodPrefab);
food.transform.SetParent(this.transform, false);
food.transform.localPosition = Vector3.zero;
return true;
}
public void LetGo() {
//Debug.Log($"{this.transform.parent.name} Release food");
List<GameObject> toDelete = new();
for (int i = 0; i < transform.childCount; i++)
toDelete.Add(transform.GetChild(i).gameObject);
foreach (GameObject go in toDelete)
Destroy(go);
havingFood?.SetBias(-Vector3.one);
}
}