From 5303db9a5965fae014217907d1ffa8febfb3e65f Mon Sep 17 00:00:00 2001 From: Sveske Juice Date: Sat, 20 Apr 2024 13:15:33 +0200 Subject: [PATCH] Rotate turret barrel --- Assets/Prefabs/Projectiles.meta | 8 ++ Assets/Prefabs/Projectiles/Bullet.prefab | 135 ++++++++++++++++++ Assets/Prefabs/Projectiles/Bullet.prefab.meta | 7 + Assets/Prefabs/Towers/Turret.prefab | 119 ++++++++++++++- Assets/Scenes/TowerTest.unity | 105 ++++++++++++++ Assets/Scripts/Tower/ProjectileTower.cs | 39 +++++ Assets/Scripts/Tower/Tower.cs | 10 +- Assets/Scripts/Utilities/EditableArc.cs | 3 + Assets/Scripts/Utilities/Observer.cs | 1 - Assets/Scripts/Utilities/ProjectileSpawner.cs | 11 +- ProjectSettings/DynamicsManager.asset | 10 +- ProjectSettings/TagManager.asset | 7 +- 12 files changed, 437 insertions(+), 18 deletions(-) create mode 100644 Assets/Prefabs/Projectiles.meta create mode 100644 Assets/Prefabs/Projectiles/Bullet.prefab create mode 100644 Assets/Prefabs/Projectiles/Bullet.prefab.meta diff --git a/Assets/Prefabs/Projectiles.meta b/Assets/Prefabs/Projectiles.meta new file mode 100644 index 0000000..4444bb0 --- /dev/null +++ b/Assets/Prefabs/Projectiles.meta @@ -0,0 +1,8 @@ +fileFormatVersion: 2 +guid: d1cbde97b5b56469fa933ef8f09f65a4 +folderAsset: yes +DefaultImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/Prefabs/Projectiles/Bullet.prefab b/Assets/Prefabs/Projectiles/Bullet.prefab new file mode 100644 index 0000000..36a7388 --- /dev/null +++ b/Assets/Prefabs/Projectiles/Bullet.prefab @@ -0,0 +1,135 @@ +%YAML 1.1 +%TAG !u! tag:unity3d.com,2011: +--- !u!1 &2962360034595352958 +GameObject: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + serializedVersion: 6 + m_Component: + - component: {fileID: 888336455889056387} + - component: {fileID: 345585203663460175} + - component: {fileID: 5408793041970514069} + - component: {fileID: 58437666630366278} + - component: {fileID: 4851113807957284959} + m_Layer: 6 + m_Name: Bullet + m_TagString: Untagged + m_Icon: {fileID: 0} + m_NavMeshLayer: 0 + m_StaticEditorFlags: 0 + m_IsActive: 1 +--- !u!4 &888336455889056387 +Transform: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 2962360034595352958} + serializedVersion: 2 + m_LocalRotation: {x: 0, y: 0, z: 0, w: 1} + m_LocalPosition: {x: 7.372555, y: -18.054228, z: 22.62589} + m_LocalScale: {x: 0.1, y: 0.1, z: 0.1} + m_ConstrainProportionsScale: 1 + m_Children: [] + m_Father: {fileID: 0} + m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} +--- !u!33 &345585203663460175 +MeshFilter: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 2962360034595352958} + m_Mesh: {fileID: 10207, guid: 0000000000000000e000000000000000, type: 0} +--- !u!23 &5408793041970514069 +MeshRenderer: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 2962360034595352958} + m_Enabled: 1 + m_CastShadows: 1 + m_ReceiveShadows: 1 + m_DynamicOccludee: 1 + m_StaticShadowCaster: 0 + m_MotionVectors: 1 + m_LightProbeUsage: 1 + m_ReflectionProbeUsage: 1 + m_RayTracingMode: 2 + m_RayTraceProcedural: 0 + m_RenderingLayerMask: 1 + m_RendererPriority: 0 + m_Materials: + - {fileID: 2100000, guid: 31321ba15b8f8eb4c954353edc038b1d, 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 + m_AdditionalVertexStreams: {fileID: 0} +--- !u!135 &58437666630366278 +SphereCollider: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 2962360034595352958} + m_Material: {fileID: 0} + m_IncludeLayers: + serializedVersion: 2 + m_Bits: 0 + m_ExcludeLayers: + serializedVersion: 2 + m_Bits: 0 + m_LayerOverridePriority: 0 + m_IsTrigger: 0 + m_ProvidesContacts: 0 + m_Enabled: 1 + serializedVersion: 3 + m_Radius: 0.5 + m_Center: {x: 0, y: 0, z: 0} +--- !u!54 &4851113807957284959 +Rigidbody: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 2962360034595352958} + serializedVersion: 4 + m_Mass: 1 + m_Drag: 0 + m_AngularDrag: 0.05 + m_CenterOfMass: {x: 0, y: 0, z: 0} + m_InertiaTensor: {x: 1, y: 1, z: 1} + m_InertiaRotation: {x: 0, y: 0, z: 0, w: 1} + m_IncludeLayers: + serializedVersion: 2 + m_Bits: 0 + m_ExcludeLayers: + serializedVersion: 2 + m_Bits: 0 + m_ImplicitCom: 1 + m_ImplicitTensor: 1 + m_UseGravity: 0 + m_IsKinematic: 0 + m_Interpolate: 0 + m_Constraints: 0 + m_CollisionDetection: 0 diff --git a/Assets/Prefabs/Projectiles/Bullet.prefab.meta b/Assets/Prefabs/Projectiles/Bullet.prefab.meta new file mode 100644 index 0000000..09a855d --- /dev/null +++ b/Assets/Prefabs/Projectiles/Bullet.prefab.meta @@ -0,0 +1,7 @@ +fileFormatVersion: 2 +guid: 32921dff6554af324ba0001ca8b56fee +PrefabImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/Prefabs/Towers/Turret.prefab b/Assets/Prefabs/Towers/Turret.prefab index 2175959..d129b1b 100644 --- a/Assets/Prefabs/Towers/Turret.prefab +++ b/Assets/Prefabs/Towers/Turret.prefab @@ -1,5 +1,110 @@ %YAML 1.1 %TAG !u! tag:unity3d.com,2011: +--- !u!1 &5590613211210629988 +GameObject: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + serializedVersion: 6 + m_Component: + - component: {fileID: 8231444434154675001} + - component: {fileID: 3249777024242727896} + - component: {fileID: 7248559923621457761} + - component: {fileID: 8492018035124418673} + m_Layer: 0 + m_Name: Barrel + m_TagString: Untagged + m_Icon: {fileID: 0} + m_NavMeshLayer: 0 + m_StaticEditorFlags: 0 + m_IsActive: 1 +--- !u!4 &8231444434154675001 +Transform: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 5590613211210629988} + serializedVersion: 2 + m_LocalRotation: {x: 0, y: 0, z: 0, w: 1} + m_LocalPosition: {x: 0, y: 0.688, z: 0} + m_LocalScale: {x: 0.1, y: 0.1, z: 0.75} + m_ConstrainProportionsScale: 0 + m_Children: [] + m_Father: {fileID: 6499929602381336473} + m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} +--- !u!33 &3249777024242727896 +MeshFilter: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 5590613211210629988} + m_Mesh: {fileID: 10202, guid: 0000000000000000e000000000000000, type: 0} +--- !u!23 &7248559923621457761 +MeshRenderer: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 5590613211210629988} + m_Enabled: 1 + m_CastShadows: 1 + m_ReceiveShadows: 1 + m_DynamicOccludee: 1 + m_StaticShadowCaster: 0 + m_MotionVectors: 1 + m_LightProbeUsage: 1 + m_ReflectionProbeUsage: 1 + m_RayTracingMode: 2 + m_RayTraceProcedural: 0 + m_RenderingLayerMask: 1 + m_RendererPriority: 0 + m_Materials: + - {fileID: 2100000, guid: 31321ba15b8f8eb4c954353edc038b1d, 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 + m_AdditionalVertexStreams: {fileID: 0} +--- !u!65 &8492018035124418673 +BoxCollider: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 5590613211210629988} + m_Material: {fileID: 0} + m_IncludeLayers: + serializedVersion: 2 + m_Bits: 0 + m_ExcludeLayers: + serializedVersion: 2 + m_Bits: 0 + m_LayerOverridePriority: 0 + m_IsTrigger: 0 + m_ProvidesContacts: 0 + m_Enabled: 1 + serializedVersion: 3 + m_Size: {x: 0.99999976, y: 1, z: 0.99999976} + m_Center: {x: -7.1054274e-15, y: 0, z: 0.000000059604638} --- !u!1001 &3629188724500721763 PrefabInstance: m_ObjectHideFlags: 0 @@ -175,7 +280,11 @@ PrefabInstance: objectReference: {fileID: 0} m_RemovedComponents: [] m_RemovedGameObjects: [] - m_AddedGameObjects: [] + m_AddedGameObjects: + - targetCorrespondingSourceObject: {fileID: 7523567070824087546, guid: c309e2ab8a7e17f049cee02d2d5e1af3, + type: 3} + insertIndex: -1 + addedObject: {fileID: 8231444434154675001} m_AddedComponents: - targetCorrespondingSourceObject: {fileID: 4241178655744724118, guid: c309e2ab8a7e17f049cee02d2d5e1af3, type: 3} @@ -242,7 +351,9 @@ MonoBehaviour: m_EditorClassIdentifier: horizontalArc: {fileID: 3156896981218152210} verticalArc: {fileID: 2419977930026982287} + attackSecondsDelay: 1 projectileSequence: [] + barrel: {fileID: 5590613211210629988} --- !u!114 &2419977930026982287 stripped MonoBehaviour: m_CorrespondingSourceObject: {fileID: 1425401315373935596, guid: c309e2ab8a7e17f049cee02d2d5e1af3, @@ -267,3 +378,9 @@ MonoBehaviour: m_Script: {fileID: 11500000, guid: 907145a413a8aab36826e850743ffdcc, type: 3} m_Name: m_EditorClassIdentifier: +--- !u!4 &6499929602381336473 stripped +Transform: + m_CorrespondingSourceObject: {fileID: 7523567070824087546, guid: c309e2ab8a7e17f049cee02d2d5e1af3, + type: 3} + m_PrefabInstance: {fileID: 3629188724500721763} + m_PrefabAsset: {fileID: 0} diff --git a/Assets/Scenes/TowerTest.unity b/Assets/Scenes/TowerTest.unity index 33c3cae..1f8304f 100644 --- a/Assets/Scenes/TowerTest.unity +++ b/Assets/Scenes/TowerTest.unity @@ -440,6 +440,31 @@ PrefabInstance: propertyPath: m_Name value: Turret objectReference: {fileID: 0} + - target: {fileID: 841175348891104259, guid: 9415cb10a1bd579269301ca4f61a1554, + type: 3} + propertyPath: projectileSequence.Array.size + value: 1 + objectReference: {fileID: 0} + - target: {fileID: 841175348891104259, guid: 9415cb10a1bd579269301ca4f61a1554, + type: 3} + propertyPath: projectileSequence.Array.data[0].Arc + value: 0 + objectReference: {fileID: 0} + - target: {fileID: 841175348891104259, guid: 9415cb10a1bd579269301ca4f61a1554, + type: 3} + propertyPath: projectileSequence.Array.data[0].Speed + value: 100 + objectReference: {fileID: 0} + - target: {fileID: 841175348891104259, guid: 9415cb10a1bd579269301ca4f61a1554, + type: 3} + propertyPath: projectileSequence.Array.data[0].Amount + value: 1 + objectReference: {fileID: 0} + - target: {fileID: 841175348891104259, guid: 9415cb10a1bd579269301ca4f61a1554, + type: 3} + propertyPath: projectileSequence.Array.data[0].bulletPrefab + value: + objectReference: {fileID: 1006877822} - target: {fileID: 6499929602381336473, guid: 9415cb10a1bd579269301ca4f61a1554, type: 3} propertyPath: m_LocalPosition.x @@ -490,11 +515,90 @@ PrefabInstance: propertyPath: m_LocalEulerAnglesHint.z value: 0 objectReference: {fileID: 0} + - target: {fileID: 7787617504657811368, guid: 9415cb10a1bd579269301ca4f61a1554, + type: 3} + propertyPath: m_Enabled + value: 0 + objectReference: {fileID: 0} m_RemovedComponents: [] m_RemovedGameObjects: [] m_AddedGameObjects: [] m_AddedComponents: [] m_SourcePrefab: {fileID: 100100000, guid: 9415cb10a1bd579269301ca4f61a1554, type: 3} +--- !u!1 &1006877822 stripped +GameObject: + m_CorrespondingSourceObject: {fileID: 2962360034595352958, guid: 32921dff6554af324ba0001ca8b56fee, + type: 3} + m_PrefabInstance: {fileID: 667212637924654954} + m_PrefabAsset: {fileID: 0} +--- !u!1001 &667212637924654954 +PrefabInstance: + m_ObjectHideFlags: 0 + serializedVersion: 2 + m_Modification: + serializedVersion: 3 + m_TransformParent: {fileID: 0} + m_Modifications: + - target: {fileID: 888336455889056387, guid: 32921dff6554af324ba0001ca8b56fee, + type: 3} + propertyPath: m_LocalPosition.x + value: 7.372555 + objectReference: {fileID: 0} + - target: {fileID: 888336455889056387, guid: 32921dff6554af324ba0001ca8b56fee, + type: 3} + propertyPath: m_LocalPosition.y + value: -18.054228 + objectReference: {fileID: 0} + - target: {fileID: 888336455889056387, guid: 32921dff6554af324ba0001ca8b56fee, + type: 3} + propertyPath: m_LocalPosition.z + value: 22.62589 + objectReference: {fileID: 0} + - target: {fileID: 888336455889056387, guid: 32921dff6554af324ba0001ca8b56fee, + type: 3} + propertyPath: m_LocalRotation.w + value: 1 + objectReference: {fileID: 0} + - target: {fileID: 888336455889056387, guid: 32921dff6554af324ba0001ca8b56fee, + type: 3} + propertyPath: m_LocalRotation.x + value: 0 + objectReference: {fileID: 0} + - target: {fileID: 888336455889056387, guid: 32921dff6554af324ba0001ca8b56fee, + type: 3} + propertyPath: m_LocalRotation.y + value: 0 + objectReference: {fileID: 0} + - target: {fileID: 888336455889056387, guid: 32921dff6554af324ba0001ca8b56fee, + type: 3} + propertyPath: m_LocalRotation.z + value: 0 + objectReference: {fileID: 0} + - target: {fileID: 888336455889056387, guid: 32921dff6554af324ba0001ca8b56fee, + type: 3} + propertyPath: m_LocalEulerAnglesHint.x + value: 0 + objectReference: {fileID: 0} + - target: {fileID: 888336455889056387, guid: 32921dff6554af324ba0001ca8b56fee, + type: 3} + propertyPath: m_LocalEulerAnglesHint.y + value: 0 + objectReference: {fileID: 0} + - target: {fileID: 888336455889056387, guid: 32921dff6554af324ba0001ca8b56fee, + type: 3} + propertyPath: m_LocalEulerAnglesHint.z + value: 0 + objectReference: {fileID: 0} + - target: {fileID: 2962360034595352958, guid: 32921dff6554af324ba0001ca8b56fee, + type: 3} + propertyPath: m_Name + value: Bullet + objectReference: {fileID: 0} + m_RemovedComponents: [] + m_RemovedGameObjects: [] + m_AddedGameObjects: [] + m_AddedComponents: [] + m_SourcePrefab: {fileID: 100100000, guid: 32921dff6554af324ba0001ca8b56fee, type: 3} --- !u!1660057539 &9223372036854775807 SceneRoots: m_ObjectHideFlags: 0 @@ -503,3 +607,4 @@ SceneRoots: - {fileID: 410087041} - {fileID: 832575519} - {fileID: 891862850} + - {fileID: 667212637924654954} diff --git a/Assets/Scripts/Tower/ProjectileTower.cs b/Assets/Scripts/Tower/ProjectileTower.cs index d0275cc..f079cc8 100644 --- a/Assets/Scripts/Tower/ProjectileTower.cs +++ b/Assets/Scripts/Tower/ProjectileTower.cs @@ -1,18 +1,57 @@ +using System; +using System.Collections; using UnityEngine; using UnityEngine.Assertions; [RequireComponent(typeof(ProjectileSpawner))] public class ProjectileTower : Tower { + [SerializeField, Range(0.01f, 20f)] private float attackSecondsDelay = 1f; [SerializeField] private ProjectilePattern[] projectileSequence; + [SerializeField] private GameObject barrel; private ProjectileSpawner projectileSpawner; + public Vector3 AimDirection => transform.TransformVector(transform.InverseTransformVector(horizontalArc.ToKnobVector) + transform.InverseTransformVector(verticalArc.ToKnobVector)); + protected override void Awake() { base.Awake(); projectileSpawner = GetComponent(); Assert.IsNotNull(projectileSpawner); + + horizontalArc.Value.AddListener(UpdateBarrelRotation); + verticalArc.Value.AddListener(UpdateBarrelRotation); + + UpdateBarrelRotation(); + StartCoroutine(AttackLoop()); + } + + protected override void OnDestroy() + { + horizontalArc.Value.RemoveListener(UpdateBarrelRotation); + verticalArc.Value.RemoveListener(UpdateBarrelRotation); + } + + private IEnumerator AttackLoop() + { + do { + yield return new WaitForSeconds(attackSecondsDelay); + UpdateBarrelRotation(); + Debug.Log("SPAWN"); + Debug.DrawRay(transform.position, horizontalArc.ToKnobVector, Color.red, attackSecondsDelay); + Debug.DrawRay(transform.position, verticalArc.ToKnobVector, Color.green, attackSecondsDelay); + Debug.DrawRay(transform.position, AimDirection, Color.yellow, attackSecondsDelay); + projectileSpawner.RunBulletSequence(transform.position, transform.up, AimDirection, projectileSequence); + } while (true); + } + + private void UpdateBarrelRotation(float unused) => UpdateBarrelRotation(); + + // Rotate barrel to match rotation + private void UpdateBarrelRotation() + { + barrel.transform.rotation = Quaternion.Euler(verticalArc.Value, horizontalArc.Value, 0f); } } diff --git a/Assets/Scripts/Tower/Tower.cs b/Assets/Scripts/Tower/Tower.cs index 2e9dd54..fc3dc5a 100644 --- a/Assets/Scripts/Tower/Tower.cs +++ b/Assets/Scripts/Tower/Tower.cs @@ -4,10 +4,10 @@ using UnityEngine.Assertions; [RequireComponent(typeof(HealthComponent))] public abstract class Tower : MonoBehaviour { - [SerializeField] private EditableArc horizontalArc; - [SerializeField] private EditableArc verticalArc; + [SerializeField] protected EditableArc horizontalArc; + [SerializeField] protected EditableArc verticalArc; - private HealthComponent healthComp; + protected HealthComponent healthComp; // Getters public Vector2 HorizontalRotationMinMax => horizontalArc.RotationMinMax; @@ -19,7 +19,9 @@ public abstract class Tower : MonoBehaviour { healthComp = GetComponent(); Assert.IsNotNull(healthComp); + } - // Set default rotation to average between min max + protected virtual void OnDestroy() + { } } diff --git a/Assets/Scripts/Utilities/EditableArc.cs b/Assets/Scripts/Utilities/EditableArc.cs index 38d2e6a..2e3ec54 100644 --- a/Assets/Scripts/Utilities/EditableArc.cs +++ b/Assets/Scripts/Utilities/EditableArc.cs @@ -27,6 +27,8 @@ public class EditableArc : MonoBehaviour public Vector3 normal => orientation == ArcOrientation.HORIZONTAL ? transform.up : transform.right; public Vector3 tangent => orientation == ArcOrientation.HORIZONTAL ? transform.right : transform.up; + public Vector3 ToKnobVector => Quaternion.AngleAxis(Value.Value, normal) * tangent; + private void Awake() { lineRenderer = GetComponent(); @@ -34,6 +36,7 @@ public class EditableArc : MonoBehaviour Value.AddListener(UpdateArc); Value.AddListener(UpdateKnobPosition); + // Set default rotation to average between min max Value.Value = (rotationMinMax.x + rotationMinMax.y) / 2f; Assert.IsNotNull(knob, $"No knob on {this}"); diff --git a/Assets/Scripts/Utilities/Observer.cs b/Assets/Scripts/Utilities/Observer.cs index 828a89b..f428d6d 100644 --- a/Assets/Scripts/Utilities/Observer.cs +++ b/Assets/Scripts/Utilities/Observer.cs @@ -32,7 +32,6 @@ public class Observer { } public void Invoke() { - Debug.Log($"Invoking {onValueChanged.GetPersistentEventCount()} listeners"); onValueChanged.Invoke(value); } diff --git a/Assets/Scripts/Utilities/ProjectileSpawner.cs b/Assets/Scripts/Utilities/ProjectileSpawner.cs index 0cb87c1..59b0381 100644 --- a/Assets/Scripts/Utilities/ProjectileSpawner.cs +++ b/Assets/Scripts/Utilities/ProjectileSpawner.cs @@ -23,12 +23,12 @@ public class ProjectileSpawner : MonoBehaviour { [SerializeField] private float delayBetweenBulletSequences = 0.1f; - public void RunBulletSequence(Vector3 origin, Vector3 baseDirection, ProjectilePattern[] bulletSequence) + public void RunBulletSequence(Vector3 origin, Vector3 normal, Vector3 baseDirection, ProjectilePattern[] bulletSequence) { - StartCoroutine(RunBulletSequenceCourotine(origin, baseDirection, bulletSequence)); + StartCoroutine(RunBulletSequenceCourotine(origin, normal, baseDirection, bulletSequence)); } - private IEnumerator RunBulletSequenceCourotine(Vector3 origin, Vector3 baseDirection, ProjectilePattern[] bulletSequence) + private IEnumerator RunBulletSequenceCourotine(Vector3 origin, Vector3 normal, Vector3 baseDirection, ProjectilePattern[] bulletSequence) { baseDirection.Normalize(); @@ -37,13 +37,14 @@ public class ProjectileSpawner : MonoBehaviour float stepSize = bulletPattern.Arc / ((float)bulletPattern.Amount); for (int i = 0; i < bulletPattern.Amount; i++) { - Vector2 bulletDir = rotate(baseDirection, stepSize * i + stepSize / 2f - bulletPattern.Arc / 2f); + float angle = stepSize * i + stepSize / 2f - bulletPattern.Arc / 2f; + Vector3 bulletDir = Quaternion.AngleAxis(angle, normal) * baseDirection; GameObject projectile = Instantiate(bulletPattern.bulletPrefab, origin, Quaternion.identity); Debug.DrawRay(origin, bulletDir, Color.magenta, 5f); projectile.transform.up = bulletDir; - projectile.GetComponent().AddForce(bulletDir * bulletPattern.Speed); + projectile.GetComponent().AddForce(bulletDir * bulletPattern.Speed); if (bulletPattern.Burst) yield return new WaitForSeconds(bulletPattern.BurstDelay); diff --git a/ProjectSettings/DynamicsManager.asset b/ProjectSettings/DynamicsManager.asset index fc90ab9..b46079b 100644 --- a/ProjectSettings/DynamicsManager.asset +++ b/ProjectSettings/DynamicsManager.asset @@ -3,10 +3,11 @@ --- !u!55 &1 PhysicsManager: m_ObjectHideFlags: 0 - serializedVersion: 13 + serializedVersion: 14 m_Gravity: {x: 0, y: -9.81, z: 0} m_DefaultMaterial: {fileID: 0} m_BounceThreshold: 2 + m_DefaultMaxDepenetrationVelocity: 10 m_SleepThreshold: 0.005 m_DefaultContactOffset: 0.01 m_DefaultSolverIterations: 6 @@ -17,10 +18,11 @@ PhysicsManager: m_ClothInterCollisionDistance: 0.1 m_ClothInterCollisionStiffness: 0.2 m_ContactsGeneration: 1 - m_LayerCollisionMatrix: ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff - m_AutoSimulation: 1 + m_LayerCollisionMatrix: ffffffffffffffffffffffffffffffffffffffffffffffffbfffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff + m_SimulationMode: 0 m_AutoSyncTransforms: 0 m_ReuseCollisionCallbacks: 1 + m_InvokeCollisionCallbacks: 1 m_ClothInterCollisionSettingsToggle: 0 m_ClothGravity: {x: 0, y: -9.81, z: 0} m_ContactPairsMode: 0 @@ -32,5 +34,7 @@ PhysicsManager: m_FrictionType: 0 m_EnableEnhancedDeterminism: 0 m_EnableUnifiedHeightmaps: 1 + m_ImprovedPatchFriction: 0 m_SolverType: 0 m_DefaultMaxAngularSpeed: 50 + m_FastMotionThreshold: 3.4028235e+38 diff --git a/ProjectSettings/TagManager.asset b/ProjectSettings/TagManager.asset index 785b035..65d15ac 100644 --- a/ProjectSettings/TagManager.asset +++ b/ProjectSettings/TagManager.asset @@ -3,8 +3,7 @@ --- !u!78 &1 TagManager: serializedVersion: 2 - tags: - - Wall + tags: [] layers: - Default - TransparentFX @@ -12,7 +11,8 @@ TagManager: - - Water - UI - - PlacementSlots + - Projectile + - - - - @@ -37,7 +37,6 @@ TagManager: - - - - - DoNotRender m_SortingLayers: - name: Default uniqueID: 0