diff --git a/Assets/Scenes/SampleScene.unity b/Assets/Scenes/SampleScene.unity index 9d74155..3dbb2f8 100644 --- a/Assets/Scenes/SampleScene.unity +++ b/Assets/Scenes/SampleScene.unity @@ -121,6 +121,99 @@ NavMeshSettings: debug: m_Flags: 0 m_NavMeshData: {fileID: 0} +--- !u!1 &33826417 +GameObject: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + serializedVersion: 6 + m_Component: + - component: {fileID: 33826421} + - component: {fileID: 33826420} + - component: {fileID: 33826419} + - component: {fileID: 33826418} + m_Layer: 0 + m_Name: Cube (3) + m_TagString: Untagged + m_Icon: {fileID: 0} + m_NavMeshLayer: 0 + m_StaticEditorFlags: 0 + m_IsActive: 1 +--- !u!65 &33826418 +BoxCollider: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 33826417} + m_Material: {fileID: 0} + m_IsTrigger: 0 + m_Enabled: 1 + serializedVersion: 2 + m_Size: {x: 1, y: 1, z: 1} + m_Center: {x: 0, y: 0, z: 0} +--- !u!23 &33826419 +MeshRenderer: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 33826417} + m_Enabled: 1 + m_CastShadows: 1 + m_ReceiveShadows: 1 + m_DynamicOccludee: 1 + m_MotionVectors: 1 + m_LightProbeUsage: 1 + m_ReflectionProbeUsage: 1 + m_RayTracingMode: 2 + m_RenderingLayerMask: 1 + m_RendererPriority: 0 + m_Materials: + - {fileID: 2100000, guid: 950d424518c282344956b5e374c7b715, type: 2} + m_StaticBatchInfo: + firstSubMesh: 0 + subMeshCount: 0 + m_StaticBatchRoot: {fileID: 0} + m_ProbeAnchor: {fileID: 0} + m_LightProbeVolumeOverride: {fileID: 0} + m_ScaleInLightmap: 1 + m_ReceiveGI: 1 + m_PreserveUVs: 0 + m_IgnoreNormalsForChartDetection: 0 + m_ImportantGI: 0 + m_StitchLightmapSeams: 1 + m_SelectedEditorRenderState: 3 + m_MinimumChartSize: 4 + m_AutoUVMaxDistance: 0.5 + m_AutoUVMaxAngle: 89 + m_LightmapParameters: {fileID: 0} + m_SortingLayerID: 0 + m_SortingLayer: 0 + m_SortingOrder: 0 +--- !u!33 &33826420 +MeshFilter: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 33826417} + m_Mesh: {fileID: 10202, guid: 0000000000000000e000000000000000, type: 0} +--- !u!4 &33826421 +Transform: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 33826417} + m_LocalRotation: {x: 0, y: -0.7071068, z: 0, w: 0.7071068} + m_LocalPosition: {x: -21.69, y: -1.012, z: 20.28} + m_LocalScale: {x: 15.892654, y: 14.241516, z: 1} + m_Children: [] + m_Father: {fileID: 0} + m_RootOrder: 5 + m_LocalEulerAnglesHint: {x: 0, y: -90, z: 0} --- !u!1 &380641380 GameObject: m_ObjectHideFlags: 0 @@ -214,6 +307,99 @@ Transform: m_Father: {fileID: 0} m_RootOrder: 3 m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} +--- !u!1 &383575962 +GameObject: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + serializedVersion: 6 + m_Component: + - component: {fileID: 383575966} + - component: {fileID: 383575965} + - component: {fileID: 383575964} + - component: {fileID: 383575963} + m_Layer: 0 + m_Name: Sphere + m_TagString: Untagged + m_Icon: {fileID: 0} + m_NavMeshLayer: 0 + m_StaticEditorFlags: 0 + m_IsActive: 1 +--- !u!135 &383575963 +SphereCollider: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 383575962} + m_Material: {fileID: 0} + m_IsTrigger: 0 + m_Enabled: 1 + serializedVersion: 2 + m_Radius: 0.5 + m_Center: {x: 0, y: 0, z: 0} +--- !u!23 &383575964 +MeshRenderer: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 383575962} + m_Enabled: 1 + m_CastShadows: 1 + m_ReceiveShadows: 1 + m_DynamicOccludee: 1 + m_MotionVectors: 1 + m_LightProbeUsage: 1 + m_ReflectionProbeUsage: 1 + m_RayTracingMode: 2 + m_RenderingLayerMask: 1 + m_RendererPriority: 0 + m_Materials: + - {fileID: 10303, guid: 0000000000000000f000000000000000, type: 0} + m_StaticBatchInfo: + firstSubMesh: 0 + subMeshCount: 0 + m_StaticBatchRoot: {fileID: 0} + m_ProbeAnchor: {fileID: 0} + m_LightProbeVolumeOverride: {fileID: 0} + m_ScaleInLightmap: 1 + m_ReceiveGI: 1 + m_PreserveUVs: 0 + m_IgnoreNormalsForChartDetection: 0 + m_ImportantGI: 0 + m_StitchLightmapSeams: 1 + m_SelectedEditorRenderState: 3 + m_MinimumChartSize: 4 + m_AutoUVMaxDistance: 0.5 + m_AutoUVMaxAngle: 89 + m_LightmapParameters: {fileID: 0} + m_SortingLayerID: 0 + m_SortingLayer: 0 + m_SortingOrder: 0 +--- !u!33 &383575965 +MeshFilter: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 383575962} + m_Mesh: {fileID: 10207, guid: 0000000000000000e000000000000000, type: 0} +--- !u!4 &383575966 +Transform: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 383575962} + m_LocalRotation: {x: 0, y: 0, z: 0, w: 1} + m_LocalPosition: {x: 0, y: -5.23, z: 7.37} + m_LocalScale: {x: 5, y: 5, z: 5} + m_Children: [] + m_Father: {fileID: 0} + m_RootOrder: 6 + m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} --- !u!1 &705507993 GameObject: m_ObjectHideFlags: 0 @@ -393,12 +579,105 @@ Transform: m_PrefabAsset: {fileID: 0} m_GameObject: {fileID: 778362041} m_LocalRotation: {x: 0, y: 0, z: 0, w: 1} - m_LocalPosition: {x: 0.8334109, y: 0.2, z: 27.1} - m_LocalScale: {x: 44.013, y: 16.279, z: 1} + m_LocalPosition: {x: 0.8334109, y: -1.012, z: 27.1} + m_LocalScale: {x: 44.013, y: 14.241516, z: 1} m_Children: [] m_Father: {fileID: 0} m_RootOrder: 4 m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} +--- !u!1 &903473255 +GameObject: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + serializedVersion: 6 + m_Component: + - component: {fileID: 903473259} + - component: {fileID: 903473258} + - component: {fileID: 903473257} + - component: {fileID: 903473256} + m_Layer: 0 + m_Name: Cube (2) + m_TagString: Untagged + m_Icon: {fileID: 0} + m_NavMeshLayer: 0 + m_StaticEditorFlags: 0 + m_IsActive: 1 +--- !u!65 &903473256 +BoxCollider: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 903473255} + m_Material: {fileID: 0} + m_IsTrigger: 0 + m_Enabled: 1 + serializedVersion: 2 + m_Size: {x: 1, y: 1, z: 1} + m_Center: {x: 0, y: 0, z: 0} +--- !u!23 &903473257 +MeshRenderer: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 903473255} + m_Enabled: 1 + m_CastShadows: 1 + m_ReceiveShadows: 1 + m_DynamicOccludee: 1 + m_MotionVectors: 1 + m_LightProbeUsage: 1 + m_ReflectionProbeUsage: 1 + m_RayTracingMode: 2 + m_RenderingLayerMask: 1 + m_RendererPriority: 0 + m_Materials: + - {fileID: 10303, guid: 0000000000000000f000000000000000, type: 0} + m_StaticBatchInfo: + firstSubMesh: 0 + subMeshCount: 0 + m_StaticBatchRoot: {fileID: 0} + m_ProbeAnchor: {fileID: 0} + m_LightProbeVolumeOverride: {fileID: 0} + m_ScaleInLightmap: 1 + m_ReceiveGI: 1 + m_PreserveUVs: 0 + m_IgnoreNormalsForChartDetection: 0 + m_ImportantGI: 0 + m_StitchLightmapSeams: 1 + m_SelectedEditorRenderState: 3 + m_MinimumChartSize: 4 + m_AutoUVMaxDistance: 0.5 + m_AutoUVMaxAngle: 89 + m_LightmapParameters: {fileID: 0} + m_SortingLayerID: 0 + m_SortingLayer: 0 + m_SortingOrder: 0 +--- !u!33 &903473258 +MeshFilter: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 903473255} + m_Mesh: {fileID: 10202, guid: 0000000000000000e000000000000000, type: 0} +--- !u!4 &903473259 +Transform: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 903473255} + m_LocalRotation: {x: -0.23348022, y: -0, z: -0, w: 0.97236156} + m_LocalPosition: {x: 9.03, y: -5.55, z: 0} + m_LocalScale: {x: 7.4761, y: 1, z: 4.4214} + m_Children: [] + m_Father: {fileID: 0} + m_RootOrder: 7 + m_LocalEulerAnglesHint: {x: -27.004002, y: 0, z: 0} --- !u!1 &963194225 GameObject: m_ObjectHideFlags: 0 @@ -544,9 +823,10 @@ MonoBehaviour: m_Name: m_EditorClassIdentifier: Prefab: {fileID: 7371939184051845554, guid: f5c2c9744b6f46e4e95ca41ab1d8d560, type: 3} - HerdCount: 20 + HerdCount: 100 SpawnPoint: {fileID: 0} WaitTime: 0.2 + Centre: {fileID: 0} --- !u!4 &1457452761 Transform: m_ObjectHideFlags: 0 diff --git a/Assets/Scripts/Input/DynamicCamera.cs b/Assets/Scripts/Input/DynamicCamera.cs index 41ceaf5..66be2bc 100644 --- a/Assets/Scripts/Input/DynamicCamera.cs +++ b/Assets/Scripts/Input/DynamicCamera.cs @@ -2,16 +2,21 @@ using System.Collections.Generic; using UnityEngine; -public class NewBehaviourScript : MonoBehaviour +public class DynamicCamera : MonoBehaviour { public GameObject target; public float camHeight; + void Start() + { + + } + void Follow() { Vector3 tempDest = target.transform.position; - tempDest.y = camHeight; - Vector3 destination = Vector3.Lerp(transform.position, tempDest, 1); + tempDest -= transform.forward * camHeight; + Vector3 destination = Vector3.Lerp(transform.position, tempDest, 10f * Time.deltaTime); transform.position = destination; } diff --git a/Assets/Scripts/Input/HerdController.cs b/Assets/Scripts/Input/HerdController.cs index 33b95ad..800986b 100644 --- a/Assets/Scripts/Input/HerdController.cs +++ b/Assets/Scripts/Input/HerdController.cs @@ -110,6 +110,12 @@ public class HerdController : MonoBehaviour Centre.position = Herd.Aggregate(new Vector3(0, 0, 0), (s, v) => s + v.transform.position) / (float)Herd.Count; } + public void RemoveHorse(PlayerController horse) + { + Herd.Remove(horse); + Destroy(horse.gameObject); + } + private bool SpawnPositionValid(Vector3 position, Quaternion rotation, Bounds bound) { diff --git a/Assets/Scripts/Input/PlayerController.cs b/Assets/Scripts/Input/PlayerController.cs index 48c5878..3f56eb2 100644 --- a/Assets/Scripts/Input/PlayerController.cs +++ b/Assets/Scripts/Input/PlayerController.cs @@ -10,6 +10,8 @@ public class PlayerController : MonoBehaviour public float gravity; public GameObject model; public CharacterController cController; + public Camera cam; + public HerdController herd; public float speedMulitplier; private float randomizer; @@ -26,6 +28,8 @@ public class PlayerController : MonoBehaviour speedMulitplier = UnityEngine.Random.Range(0.8f, 1.2f); cController = GetComponent(); randomizer = UnityEngine.Random.Range(0,10); + cam = FindObjectOfType(); + herd = FindObjectOfType(); } public void SetMovement(Vector2 input) @@ -38,22 +42,21 @@ public class PlayerController : MonoBehaviour moveDelta = Time.time - lastMoveTime; lastMoveTime = Time.time; - - if (receivedInput.magnitude == 0) - return; - float HorseX, HorseZ; HorseZ = receivedInput.y; HorseX = receivedInput.x; - if (Mathf.Abs(HorseZ) == Mathf.Min(Mathf.Abs(HorseZ), Mathf.Abs(HorseX))) + if (receivedInput.magnitude != 0) { - HorseZ += directionRandmoizer; + if (Mathf.Abs(HorseZ) == Mathf.Min(Mathf.Abs(HorseZ), Mathf.Abs(HorseX))) + { + HorseZ += directionRandmoizer; + } + else + { + HorseX += directionRandmoizer; + } } - else - { - HorseX += directionRandmoizer; - } - + if (cController.isGrounded) { moveDirection = new Vector3(HorseX, 0, HorseZ); @@ -123,13 +126,20 @@ public class PlayerController : MonoBehaviour } } + public void DestroyOffCamera() + { + Vector3 viewPos = cam.WorldToViewportPoint(transform.position); + if (viewPos.y < -0.1) + herd.RemoveHorse(this); + } + // Update is called once per frame void Update() { - speedMulitplier = (Mathf.Sin(Time.time * UnityEngine.Random.Range(0.9f,1.1f) + randomizer) + 2); directionRandmoizer = Mathf.Cos(Time.time + randomizer / 2) * 0.3f; UpdatePosition(); + DestroyOffCamera(); } public void AddForce(Vector3 direction) diff --git a/Assets/WorldAssets/Prefabs/Horse.prefab b/Assets/WorldAssets/Prefabs/Horse.prefab index fa1b80c..cb1e419 100644 --- a/Assets/WorldAssets/Prefabs/Horse.prefab +++ b/Assets/WorldAssets/Prefabs/Horse.prefab @@ -81,6 +81,7 @@ MonoBehaviour: gravity: 35 model: {fileID: 760734042007802935} cController: {fileID: 0} + speedMulitplier: 0 --- !u!143 &7371939184051845555 CharacterController: m_ObjectHideFlags: 0