From cca6af8109d87c99af87746d1d032c456d178b5a Mon Sep 17 00:00:00 2001 From: Sveske Juice Date: Fri, 2 Feb 2024 16:14:34 -0800 Subject: [PATCH 1/2] squeze damage from rope --- Assets/Scenes/RopeTest.unity | 140 +++++++++++++++++- Assets/Scripts/Player/HealthComponent.cs | 46 ++++++ ...ayerHP.cs.meta => HealthComponent.cs.meta} | 0 Assets/Scripts/Player/PlayerHP.cs | 37 ----- Assets/Scripts/Rope/ISquezeDamageReceiver.cs | 4 + .../Rope/ISquezeDamageReceiver.cs.meta | 11 ++ Assets/Scripts/Rope/RopeSimulator.cs | 28 +++- Assets/Scripts/UI.meta | 8 + Assets/Scripts/UI/HealthDisplay.cs | 31 ++++ Assets/Scripts/UI/HealthDisplay.cs.meta | 11 ++ 10 files changed, 271 insertions(+), 45 deletions(-) create mode 100644 Assets/Scripts/Player/HealthComponent.cs rename Assets/Scripts/Player/{PlayerHP.cs.meta => HealthComponent.cs.meta} (100%) delete mode 100644 Assets/Scripts/Player/PlayerHP.cs create mode 100644 Assets/Scripts/Rope/ISquezeDamageReceiver.cs create mode 100644 Assets/Scripts/Rope/ISquezeDamageReceiver.cs.meta create mode 100644 Assets/Scripts/UI.meta create mode 100644 Assets/Scripts/UI/HealthDisplay.cs create mode 100644 Assets/Scripts/UI/HealthDisplay.cs.meta diff --git a/Assets/Scenes/RopeTest.unity b/Assets/Scenes/RopeTest.unity index ffb2742..ccd865a 100644 --- a/Assets/Scenes/RopeTest.unity +++ b/Assets/Scenes/RopeTest.unity @@ -135,6 +135,7 @@ GameObject: - component: {fileID: 347555805} - component: {fileID: 347555804} - component: {fileID: 347555803} + - component: {fileID: 347555807} m_Layer: 0 m_Name: EnemyTest (3) m_TagString: Untagged @@ -271,6 +272,39 @@ Transform: m_Children: [] m_Father: {fileID: 0} m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} +--- !u!114 &347555807 +MonoBehaviour: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 347555802} + m_Enabled: 1 + m_EditorHideFlags: 0 + m_Script: {fileID: 11500000, guid: 1fdfc885f1a69704b893825cf9e616ba, type: 3} + m_Name: + m_EditorClassIdentifier: + maxHealth: 100 + OnHealthZero: + m_PersistentCalls: + m_Calls: + - m_Target: {fileID: 347555807} + m_TargetAssemblyTypeName: HealthComponent, Assembly-CSharp + m_MethodName: SimpleKill + m_Mode: 1 + m_Arguments: + m_ObjectArgument: {fileID: 0} + m_ObjectArgumentAssemblyTypeName: UnityEngine.Object, UnityEngine + m_IntArgument: 0 + m_FloatArgument: 0 + m_StringArgument: + m_BoolArgument: 0 + m_CallState: 2 + OnHealthChange: + m_PersistentCalls: + m_Calls: [] + minThreshold: 1 + squezeDamageScalor: 1 --- !u!1 &418427021 GameObject: m_ObjectHideFlags: 0 @@ -283,6 +317,7 @@ GameObject: - component: {fileID: 418427024} - component: {fileID: 418427023} - component: {fileID: 418427022} + - component: {fileID: 418427026} m_Layer: 0 m_Name: EnemyTest (4) m_TagString: Untagged @@ -419,6 +454,39 @@ Transform: m_Children: [] m_Father: {fileID: 0} m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} +--- !u!114 &418427026 +MonoBehaviour: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 418427021} + m_Enabled: 1 + m_EditorHideFlags: 0 + m_Script: {fileID: 11500000, guid: 1fdfc885f1a69704b893825cf9e616ba, type: 3} + m_Name: + m_EditorClassIdentifier: + maxHealth: 100 + OnHealthZero: + m_PersistentCalls: + m_Calls: + - m_Target: {fileID: 418427026} + m_TargetAssemblyTypeName: HealthComponent, Assembly-CSharp + m_MethodName: SimpleKill + m_Mode: 1 + m_Arguments: + m_ObjectArgument: {fileID: 0} + m_ObjectArgumentAssemblyTypeName: UnityEngine.Object, UnityEngine + m_IntArgument: 0 + m_FloatArgument: 0 + m_StringArgument: + m_BoolArgument: 0 + m_CallState: 2 + OnHealthChange: + m_PersistentCalls: + m_Calls: [] + minThreshold: 1 + squezeDamageScalor: 1 --- !u!1 &437176298 GameObject: m_ObjectHideFlags: 0 @@ -431,6 +499,7 @@ GameObject: - component: {fileID: 437176300} - component: {fileID: 437176299} - component: {fileID: 437176302} + - component: {fileID: 437176303} m_Layer: 0 m_Name: EnemyTest (2) m_TagString: Untagged @@ -567,6 +636,39 @@ Rigidbody2D: m_SleepingMode: 1 m_CollisionDetection: 1 m_Constraints: 0 +--- !u!114 &437176303 +MonoBehaviour: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 437176298} + m_Enabled: 1 + m_EditorHideFlags: 0 + m_Script: {fileID: 11500000, guid: 1fdfc885f1a69704b893825cf9e616ba, type: 3} + m_Name: + m_EditorClassIdentifier: + maxHealth: 100 + OnHealthZero: + m_PersistentCalls: + m_Calls: + - m_Target: {fileID: 437176303} + m_TargetAssemblyTypeName: HealthComponent, Assembly-CSharp + m_MethodName: SimpleKill + m_Mode: 1 + m_Arguments: + m_ObjectArgument: {fileID: 0} + m_ObjectArgumentAssemblyTypeName: UnityEngine.Object, UnityEngine + m_IntArgument: 0 + m_FloatArgument: 0 + m_StringArgument: + m_BoolArgument: 0 + m_CallState: 2 + OnHealthChange: + m_PersistentCalls: + m_Calls: [] + minThreshold: 1 + squezeDamageScalor: 1 --- !u!1 &442848047 GameObject: m_ObjectHideFlags: 0 @@ -578,6 +680,7 @@ GameObject: - component: {fileID: 442848048} - component: {fileID: 442848050} - component: {fileID: 442848049} + - component: {fileID: 442848051} m_Layer: 5 m_Name: Health m_TagString: Untagged @@ -701,6 +804,21 @@ CanvasRenderer: m_PrefabAsset: {fileID: 0} m_GameObject: {fileID: 442848047} m_CullTransparentMesh: 1 +--- !u!114 &442848051 +MonoBehaviour: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 442848047} + m_Enabled: 1 + m_EditorHideFlags: 0 + m_Script: {fileID: 11500000, guid: 6ea817cc94396c24199c7d5b0f34e889, type: 3} + m_Name: + m_EditorClassIdentifier: + padding: 'Health: ' + healthText: {fileID: 442848049} + healthComponent: {fileID: 1451580751} --- !u!1 &484915623 GameObject: m_ObjectHideFlags: 0 @@ -919,8 +1037,26 @@ MonoBehaviour: m_Name: m_EditorClassIdentifier: maxHealth: 100 - currentHealth: 0 - healthText: {fileID: 442848049} + OnHealthZero: + m_PersistentCalls: + m_Calls: + - m_Target: {fileID: 1451580751} + m_TargetAssemblyTypeName: HealthComponent, Assembly-CSharp + m_MethodName: SimpleKill + m_Mode: 1 + m_Arguments: + m_ObjectArgument: {fileID: 0} + m_ObjectArgumentAssemblyTypeName: UnityEngine.Object, UnityEngine + m_IntArgument: 0 + m_FloatArgument: 0 + m_StringArgument: + m_BoolArgument: 0 + m_CallState: 2 + OnHealthChange: + m_PersistentCalls: + m_Calls: [] + minThreshold: 1 + squezeDamageScalor: 0 --- !u!114 &1451580752 MonoBehaviour: m_ObjectHideFlags: 0 diff --git a/Assets/Scripts/Player/HealthComponent.cs b/Assets/Scripts/Player/HealthComponent.cs new file mode 100644 index 0000000..d02a05f --- /dev/null +++ b/Assets/Scripts/Player/HealthComponent.cs @@ -0,0 +1,46 @@ +using UnityEngine; +using UnityEngine.Events; +using TMPro; + +public class HealthComponent : MonoBehaviour, ISquezeDamageReceiver +{ + [SerializeField] int maxHealth = 100; + public int currentHealth { get; private set; } + + public UnityEvent OnHealthZero; + public UnityEvent OnHealthChange; + + [Header("Squeze Damage")] + [SerializeField] + float minThreshold = 1f; + + [SerializeField] + float squezeDamageScalor = 1f; + + void Awake() + { + currentHealth = maxHealth; + } + + public void TakeDamage(int damage) + { + currentHealth -= damage; + OnHealthChange?.Invoke(currentHealth + damage, currentHealth); + + if (currentHealth <= 0) + OnHealthZero?.Invoke(); + } + + public void TakeSquezeDamage(float squezeDamage) + { + Debug.Log($"Taking {squezeDamage}"); + if (squezeDamage < minThreshold) return; + + TakeDamage((int) Mathf.Round(squezeDamage * squezeDamageScalor)); + } + + public void SimpleKill() + { + Destroy(gameObject); + } +} diff --git a/Assets/Scripts/Player/PlayerHP.cs.meta b/Assets/Scripts/Player/HealthComponent.cs.meta similarity index 100% rename from Assets/Scripts/Player/PlayerHP.cs.meta rename to Assets/Scripts/Player/HealthComponent.cs.meta diff --git a/Assets/Scripts/Player/PlayerHP.cs b/Assets/Scripts/Player/PlayerHP.cs deleted file mode 100644 index 9c70ec6..0000000 --- a/Assets/Scripts/Player/PlayerHP.cs +++ /dev/null @@ -1,37 +0,0 @@ -using System.Collections; -using System.Collections.Generic; -using UnityEngine; -using TMPro; - -public class PlayerHP : MonoBehaviour -{ - public int maxHealth = 100; - public int currentHealth; - public TextMeshProUGUI healthText; - void Start() - { - currentHealth = maxHealth; - } - - public void Update() - { - if (currentHealth <= 0) - { - // TODO: Game Over - } - if (healthText != null && currentHealth > 0) - { - healthText.text = "Health: " + currentHealth; - } - else if (healthText != null && currentHealth <= 0) - healthText.text = "Health: 0"; - - if (Input.GetKeyDown(KeyCode.Space)) - TakeDamage(5); - } - - public void TakeDamage(float damage) - { - currentHealth -= (int)damage; - } -} diff --git a/Assets/Scripts/Rope/ISquezeDamageReceiver.cs b/Assets/Scripts/Rope/ISquezeDamageReceiver.cs new file mode 100644 index 0000000..8b83043 --- /dev/null +++ b/Assets/Scripts/Rope/ISquezeDamageReceiver.cs @@ -0,0 +1,4 @@ +public interface ISquezeDamageReceiver +{ + public void TakeSquezeDamage(float squezeDamage); +} \ No newline at end of file diff --git a/Assets/Scripts/Rope/ISquezeDamageReceiver.cs.meta b/Assets/Scripts/Rope/ISquezeDamageReceiver.cs.meta new file mode 100644 index 0000000..50d1188 --- /dev/null +++ b/Assets/Scripts/Rope/ISquezeDamageReceiver.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: d31d8fbcb6322ba4ba6891dba7d49bd0 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/Scripts/Rope/RopeSimulator.cs b/Assets/Scripts/Rope/RopeSimulator.cs index b418554..729df7a 100644 --- a/Assets/Scripts/Rope/RopeSimulator.cs +++ b/Assets/Scripts/Rope/RopeSimulator.cs @@ -51,10 +51,10 @@ public class RopeSimulator : MonoBehaviour public Vector2 testPos; - Vector2 prevStartPos; - Rope rope; + Dictionary colliderToSquezeForce = new(); + private void Start() { //rope = new RopeBuilder() @@ -100,6 +100,8 @@ public class RopeSimulator : MonoBehaviour private void Update() { + colliderToSquezeForce.Clear(); + rope.points.First().position = start.position; rope.points.Last().position = end.position; @@ -128,7 +130,14 @@ public class RopeSimulator : MonoBehaviour start.gameObject.GetComponent().AddForce(pullDirection * overshoot * pullForce); } - prevStartPos = start.position; + // Handle squeze kills + foreach (var collider in colliderToSquezeForce) + { + ISquezeDamageReceiver squezeDamageReceiver = collider.Key.GetComponent(); + if (squezeDamageReceiver == null) continue; + + squezeDamageReceiver.TakeSquezeDamage(collider.Value); + } } private void OnDrawGizmos() @@ -216,10 +225,17 @@ public class RopeSimulator : MonoBehaviour Collider2D hitCollider = Physics2D.OverlapCircle(p.position, ropeRadius, staticColliderMask); if (hitCollider == null) return; + // Register the squeze force this rope particle is squezing the collider Vector2 resolvedPos = hitCollider.ClosestPoint(p.position); - Vector2 penetrationDir = (resolvedPos - p.position).normalized; - Vector2 finalPos = resolvedPos - penetrationDir * ropeRadius; - + Vector2 penetration = resolvedPos - p.position; + Vector2 finalPos = resolvedPos - penetration.normalized * ropeRadius; + + float squezeForce; + if (!colliderToSquezeForce.TryGetValue(hitCollider, out squezeForce)) + colliderToSquezeForce.Add(hitCollider, squezeForce + penetration.magnitude); + else + colliderToSquezeForce[hitCollider] = squezeForce + penetration.magnitude; + p.position = finalPos; } diff --git a/Assets/Scripts/UI.meta b/Assets/Scripts/UI.meta new file mode 100644 index 0000000..5af4230 --- /dev/null +++ b/Assets/Scripts/UI.meta @@ -0,0 +1,8 @@ +fileFormatVersion: 2 +guid: 8b645cb8aa203484aaefb2b6f86e696c +folderAsset: yes +DefaultImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/Scripts/UI/HealthDisplay.cs b/Assets/Scripts/UI/HealthDisplay.cs new file mode 100644 index 0000000..ae7af02 --- /dev/null +++ b/Assets/Scripts/UI/HealthDisplay.cs @@ -0,0 +1,31 @@ +using System.Collections; +using System.Collections.Generic; +using UnityEngine; +using TMPro; + +public class HealthDisplay : MonoBehaviour +{ + [SerializeField] string padding = "Health: "; + [SerializeField] TextMeshProUGUI healthText; + [SerializeField] HealthComponent healthComponent; + + private void Start() + { + healthText.text = padding + healthComponent.currentHealth; + } + + private void OnEnable() + { + healthComponent.OnHealthChange.AddListener(UpdateHealth); + } + + private void OnDisable() + { + healthComponent.OnHealthChange.RemoveListener(UpdateHealth); + } + + public void UpdateHealth(int prevHealth, int newHealth) + { + healthText.text = padding + healthComponent.currentHealth; + } +} diff --git a/Assets/Scripts/UI/HealthDisplay.cs.meta b/Assets/Scripts/UI/HealthDisplay.cs.meta new file mode 100644 index 0000000..36b9a51 --- /dev/null +++ b/Assets/Scripts/UI/HealthDisplay.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 6ea817cc94396c24199c7d5b0f34e889 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: From 0f44990843fff3f390ed7c7af2c19e02d2f31be7 Mon Sep 17 00:00:00 2001 From: Sveske Juice Date: Fri, 2 Feb 2024 16:25:34 -0800 Subject: [PATCH 2/2] simple line renderer --- Assets/Materials.meta | 8 ++ Assets/Materials/Rope.mat | 148 +++++++++++++++++++++++++++ Assets/Materials/Rope.mat.meta | 8 ++ Assets/Scenes/RopeTest.unity | 106 +++++++++++++++++++ Assets/Scripts/Rope/RopeSimulator.cs | 8 ++ 5 files changed, 278 insertions(+) create mode 100644 Assets/Materials.meta create mode 100644 Assets/Materials/Rope.mat create mode 100644 Assets/Materials/Rope.mat.meta diff --git a/Assets/Materials.meta b/Assets/Materials.meta new file mode 100644 index 0000000..54e65d7 --- /dev/null +++ b/Assets/Materials.meta @@ -0,0 +1,8 @@ +fileFormatVersion: 2 +guid: 98edd43838a689944bf8b51dc59cb761 +folderAsset: yes +DefaultImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/Materials/Rope.mat b/Assets/Materials/Rope.mat new file mode 100644 index 0000000..a9c9851 --- /dev/null +++ b/Assets/Materials/Rope.mat @@ -0,0 +1,148 @@ +%YAML 1.1 +%TAG !u! tag:unity3d.com,2011: +--- !u!114 &-2249664144050529756 +MonoBehaviour: + m_ObjectHideFlags: 11 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 0} + m_Enabled: 1 + m_EditorHideFlags: 0 + m_Script: {fileID: 11500000, guid: d0353a89b1f911e48b9e16bdc9f2e058, type: 3} + m_Name: + m_EditorClassIdentifier: + version: 7 +--- !u!21 &2100000 +Material: + serializedVersion: 8 + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_Name: Rope + m_Shader: {fileID: 4800000, guid: 933532a4fcc9baf4fa0491de14d08ed7, type: 3} + m_Parent: {fileID: 0} + m_ModifiedSerializedProperties: 0 + m_ValidKeywords: [] + m_InvalidKeywords: [] + m_LightmapFlags: 4 + m_EnableInstancingVariants: 0 + m_DoubleSidedGI: 0 + m_CustomRenderQueue: -1 + stringTagMap: + RenderType: Opaque + disabledShaderPasses: [] + m_LockedProperties: + m_SavedProperties: + serializedVersion: 3 + m_TexEnvs: + - _AlphaTex: + m_Texture: {fileID: 0} + m_Scale: {x: 1, y: 1} + m_Offset: {x: 0, y: 0} + - _BaseMap: + m_Texture: {fileID: 0} + m_Scale: {x: 1, y: 1} + m_Offset: {x: 0, y: 0} + - _BumpMap: + m_Texture: {fileID: 0} + m_Scale: {x: 1, y: 1} + m_Offset: {x: 0, y: 0} + - _DetailAlbedoMap: + m_Texture: {fileID: 0} + m_Scale: {x: 1, y: 1} + m_Offset: {x: 0, y: 0} + - _DetailMask: + m_Texture: {fileID: 0} + m_Scale: {x: 1, y: 1} + m_Offset: {x: 0, y: 0} + - _DetailNormalMap: + m_Texture: {fileID: 0} + m_Scale: {x: 1, y: 1} + m_Offset: {x: 0, y: 0} + - _EmissionMap: + m_Texture: {fileID: 0} + m_Scale: {x: 1, y: 1} + m_Offset: {x: 0, y: 0} + - _MainTex: + m_Texture: {fileID: 0} + m_Scale: {x: 1, y: 1} + m_Offset: {x: 0, y: 0} + - _MaskTex: + m_Texture: {fileID: 0} + m_Scale: {x: 1, y: 1} + m_Offset: {x: 0, y: 0} + - _MetallicGlossMap: + m_Texture: {fileID: 0} + m_Scale: {x: 1, y: 1} + m_Offset: {x: 0, y: 0} + - _NormalMap: + m_Texture: {fileID: 0} + m_Scale: {x: 1, y: 1} + m_Offset: {x: 0, y: 0} + - _OcclusionMap: + m_Texture: {fileID: 0} + m_Scale: {x: 1, y: 1} + m_Offset: {x: 0, y: 0} + - _ParallaxMap: + m_Texture: {fileID: 0} + m_Scale: {x: 1, y: 1} + m_Offset: {x: 0, y: 0} + - _SpecGlossMap: + m_Texture: {fileID: 0} + m_Scale: {x: 1, y: 1} + m_Offset: {x: 0, y: 0} + - unity_Lightmaps: + m_Texture: {fileID: 0} + m_Scale: {x: 1, y: 1} + m_Offset: {x: 0, y: 0} + - unity_LightmapsInd: + m_Texture: {fileID: 0} + m_Scale: {x: 1, y: 1} + m_Offset: {x: 0, y: 0} + - unity_ShadowMasks: + m_Texture: {fileID: 0} + m_Scale: {x: 1, y: 1} + m_Offset: {x: 0, y: 0} + m_Ints: [] + m_Floats: + - _AlphaClip: 0 + - _AlphaToMask: 0 + - _Blend: 0 + - _BlendModePreserveSpecular: 1 + - _BumpScale: 1 + - _ClearCoatMask: 0 + - _ClearCoatSmoothness: 0 + - _Cull: 2 + - _Cutoff: 0.5 + - _DetailAlbedoMapScale: 1 + - _DetailNormalMapScale: 1 + - _DstBlend: 0 + - _DstBlendAlpha: 0 + - _EnableExternalAlpha: 0 + - _EnvironmentReflections: 1 + - _GlossMapScale: 0 + - _Glossiness: 0 + - _GlossyReflections: 0 + - _Metallic: 0 + - _OcclusionStrength: 1 + - _Parallax: 0.005 + - _QueueOffset: 0 + - _ReceiveShadows: 1 + - _Smoothness: 0.202 + - _SmoothnessTextureChannel: 0 + - _SpecularHighlights: 1 + - _SrcBlend: 1 + - _SrcBlendAlpha: 1 + - _Surface: 0 + - _WorkflowMode: 1 + - _ZWrite: 1 + m_Colors: + - _BaseColor: {r: 0.554717, g: 0.2277991, b: 0.032445684, a: 1} + - _Color: {r: 0.554717, g: 0.22779906, b: 0.032445684, a: 1} + - _EmissionColor: {r: 0, g: 0, b: 0, a: 1} + - _Flip: {r: 1, g: 1, b: 1, a: 1} + - _RendererColor: {r: 1, g: 1, b: 1, a: 1} + - _SpecColor: {r: 0.19999996, g: 0.19999996, b: 0.19999996, a: 1} + m_BuildTextureStacks: [] diff --git a/Assets/Materials/Rope.mat.meta b/Assets/Materials/Rope.mat.meta new file mode 100644 index 0000000..3c73354 --- /dev/null +++ b/Assets/Materials/Rope.mat.meta @@ -0,0 +1,8 @@ +fileFormatVersion: 2 +guid: 62e10f2f26f232f49affb7663a8064fb +NativeFormatImporter: + externalObjects: {} + mainObjectFileID: 2100000 + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/Scenes/RopeTest.unity b/Assets/Scenes/RopeTest.unity index ccd865a..580faa1 100644 --- a/Assets/Scenes/RopeTest.unity +++ b/Assets/Scenes/RopeTest.unity @@ -1480,6 +1480,7 @@ GameObject: m_Component: - component: {fileID: 1973576216} - component: {fileID: 1973576217} + - component: {fileID: 1973576218} m_Layer: 0 m_Name: Rope m_TagString: Untagged @@ -1529,7 +1530,112 @@ MonoBehaviour: serializedVersion: 2 m_Bits: 1 pullForce: 65 + lineRenderer: {fileID: 1973576218} testPos: {x: 0, y: 0} +--- !u!120 &1973576218 +LineRenderer: + serializedVersion: 2 + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 1973576215} + m_Enabled: 1 + m_CastShadows: 1 + m_ReceiveShadows: 1 + m_DynamicOccludee: 1 + m_StaticShadowCaster: 0 + m_MotionVectors: 0 + m_LightProbeUsage: 0 + m_ReflectionProbeUsage: 0 + m_RayTracingMode: 0 + m_RayTraceProcedural: 0 + m_RenderingLayerMask: 1 + m_RendererPriority: 0 + m_Materials: + - {fileID: 2100000, guid: 62e10f2f26f232f49affb7663a8064fb, 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_Positions: + - {x: 0, y: 0, z: 0} + - {x: 0, y: 0, z: 1} + m_Parameters: + serializedVersion: 3 + widthMultiplier: 1 + widthCurve: + serializedVersion: 2 + m_Curve: + - serializedVersion: 3 + time: 0 + value: 0.2280693 + inSlope: 0 + outSlope: 0 + tangentMode: 0 + weightedMode: 0 + inWeight: 0.33333334 + outWeight: 0.33333334 + m_PreInfinity: 2 + m_PostInfinity: 2 + m_RotationOrder: 4 + colorGradient: + serializedVersion: 2 + key0: {r: 1, g: 1, b: 1, a: 1} + key1: {r: 1, g: 1, b: 1, a: 1} + key2: {r: 0, g: 0, b: 0, a: 0} + key3: {r: 0, g: 0, b: 0, a: 0} + key4: {r: 0, g: 0, b: 0, a: 0} + key5: {r: 0, g: 0, b: 0, a: 0} + key6: {r: 0, g: 0, b: 0, a: 0} + key7: {r: 0, g: 0, b: 0, a: 0} + ctime0: 0 + ctime1: 65535 + ctime2: 0 + ctime3: 0 + ctime4: 0 + ctime5: 0 + ctime6: 0 + ctime7: 0 + atime0: 0 + atime1: 65535 + atime2: 0 + atime3: 0 + atime4: 0 + atime5: 0 + atime6: 0 + atime7: 0 + m_Mode: 0 + m_ColorSpace: -1 + m_NumColorKeys: 2 + m_NumAlphaKeys: 2 + numCornerVertices: 0 + numCapVertices: 0 + alignment: 0 + textureMode: 0 + textureScale: {x: 1, y: 1} + shadowBias: 0.5 + generateLightingData: 0 + m_MaskInteraction: 0 + m_UseWorldSpace: 1 + m_Loop: 0 + m_ApplyActiveColorSpace: 1 --- !u!1 &1993214202 GameObject: m_ObjectHideFlags: 0 diff --git a/Assets/Scripts/Rope/RopeSimulator.cs b/Assets/Scripts/Rope/RopeSimulator.cs index 729df7a..4fc35c5 100644 --- a/Assets/Scripts/Rope/RopeSimulator.cs +++ b/Assets/Scripts/Rope/RopeSimulator.cs @@ -47,6 +47,9 @@ public class RopeSimulator : MonoBehaviour [SerializeField, Range(0f, 100f)] float pullForce = 20f; + [Header("Rendering")] + [SerializeField] LineRenderer lineRenderer; + int[] order; public Vector2 testPos; @@ -138,6 +141,11 @@ public class RopeSimulator : MonoBehaviour squezeDamageReceiver.TakeSquezeDamage(collider.Value); } + + // Update line renderer + var positions = rope.points.Select(p => new Vector3(p.position.x, p.position.y, 0f)).ToArray(); + lineRenderer.positionCount = positions.Length; + lineRenderer.SetPositions(positions); } private void OnDrawGizmos()