diff --git a/Assets/InputSystem.inputsettings.asset b/Assets/InputSystem.inputsettings.asset new file mode 100644 index 0000000..170571f --- /dev/null +++ b/Assets/InputSystem.inputsettings.asset @@ -0,0 +1,36 @@ +%YAML 1.1 +%TAG !u! tag:unity3d.com,2011: +--- !u!114 &11400000 +MonoBehaviour: + m_ObjectHideFlags: 0 + 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: c46f07b5ed07e4e92aa78254188d3d10, type: 3} + m_Name: InputSystem.inputsettings + m_EditorClassIdentifier: + m_SupportedDevices: [] + m_UpdateMode: 1 + m_MaxEventBytesPerUpdate: 5242880 + m_MaxQueuedEventsPerUpdate: 1000 + m_CompensateForScreenOrientation: 1 + m_BackgroundBehavior: 0 + m_EditorInputBehaviorInPlayMode: 0 + m_DefaultDeadzoneMin: 0.125 + m_DefaultDeadzoneMax: 0.925 + m_DefaultButtonPressPoint: 0.5 + m_ButtonReleaseThreshold: 0.75 + m_DefaultTapTime: 0.2 + m_DefaultSlowTapTime: 0.5 + m_DefaultHoldTime: 0.4 + m_TapRadius: 5 + m_MultiTapDelayTime: 0.75 + m_DisableRedundantEventsMerging: 0 + m_ShortcutKeysConsumeInputs: 0 + m_iOSSettings: + m_MotionUsage: + m_Enabled: 0 + m_Description: diff --git a/Assets/InputSystem.inputsettings.asset.meta b/Assets/InputSystem.inputsettings.asset.meta new file mode 100644 index 0000000..42c1c1a --- /dev/null +++ b/Assets/InputSystem.inputsettings.asset.meta @@ -0,0 +1,8 @@ +fileFormatVersion: 2 +guid: de04e34f85a966e4da851d9b3d804fa1 +NativeFormatImporter: + externalObjects: {} + mainObjectFileID: 11400000 + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/Scenes/EnemyRope.unity b/Assets/Scenes/EnemyRope.unity index 76982f4..8c81864 100644 --- a/Assets/Scenes/EnemyRope.unity +++ b/Assets/Scenes/EnemyRope.unity @@ -2072,7 +2072,7 @@ MonoBehaviour: end: {fileID: 1259212308} subDivision: 50 collisionCheckDist: 0.1 - distBetweenRopePoints: 0.3 + distBetweenRopePoints: 0.35 ropeRadius: 0.171 ignoreResolveThreshold: 0 ropeCollidersParent: {fileID: 1647138193} @@ -2081,9 +2081,10 @@ MonoBehaviour: m_Bits: 1 pullForce: 65 xyGravityDampScalor: 1 - ropeExtendSpeed: 15 + ropeExtendSpeed: 10 ropeShrinkSpeed: 15 - ropeMaxLength: 0 + ropeMaxLength: 50 + ropeMinLength: 20 lineRenderer: {fileID: 1647138191} --- !u!4 &1647138193 Transform: diff --git a/Assets/Scripts/Player/PlayerInput.cs b/Assets/Scripts/Player/PlayerInput.cs index fc63bad..3497fea 100644 --- a/Assets/Scripts/Player/PlayerInput.cs +++ b/Assets/Scripts/Player/PlayerInput.cs @@ -19,7 +19,7 @@ public class PlayerInput : MonoBehaviour public int PlayerNum => playerNumber; - private void Awake() + private void Start() { controller = Gamepad.all.ElementAtOrDefault(playerNumber); if (controller == null) diff --git a/Assets/Scripts/Rope/Rope.cs b/Assets/Scripts/Rope/Rope.cs index 370ac94..432085c 100644 --- a/Assets/Scripts/Rope/Rope.cs +++ b/Assets/Scripts/Rope/Rope.cs @@ -17,6 +17,7 @@ public class Rope float sum = 0f; foreach (Stick stick in sticks) { + Debug.DrawRay(stick.B.position, (stick.A.position - stick.B.position).normalized * stick.desiredLength); float dist = Vector3.Distance(stick.A.position, stick.B.position); sum += dist - stick.desiredLength; } diff --git a/Assets/Scripts/Rope/RopeSimulator.cs b/Assets/Scripts/Rope/RopeSimulator.cs index a8d0777..8001865 100644 --- a/Assets/Scripts/Rope/RopeSimulator.cs +++ b/Assets/Scripts/Rope/RopeSimulator.cs @@ -94,48 +94,57 @@ public class RopeSimulator : MonoBehaviour if (subDivision < ropeMinLength) subDivision = ropeMinLength; - if (prevSubDivision - (int)subDivision > 0) return; + if (prevSubDivision - (int)subDivision <= 0) return; // Shrink from start - if (playerNumber == start.playerInput.PlayerNum) + rope.sticks.Clear(); + rope.points.RemoveAt(1); + + var builder = new RopeBuilder(rope.points, rope.sticks); + + // Re-gen sticks + for (int i = 0; i < (int) subDivision; i++) { - rope.sticks.Clear(); - rope.points.RemoveAt(0); - - var builder = new RopeBuilder(rope.points, new List()); - - // Re-gen sticks - for (int i = 0; i < (int) subDivision; i++) - { - builder.ConnectPoints(i, i + 1); - } - rope = builder.Build(); + builder.ConnectPointsWithDesiredLength(i, i + 1, distBetweenRopePoints); } - // Shrink from end - else if (playerNumber == end.playerInput.PlayerNum) - { - rope.points.RemoveAt(rope.points.Count - 2); - rope.sticks.Clear(); + rope = builder.Build(); - var builder = new RopeBuilder(rope.points, new List()); - - // Re-gen sticks - for (int i = 0; i < (int)subDivision; i++) - { - builder.ConnectPoints(i, i + 1); - } - rope = builder.Build(); - } + RebuildRopeColliders(); CreateOrderArray(); } void ExtendRope(int playerNumber) { + int prevSubDivision = (int)subDivision; subDivision += ropeExtendSpeed * Time.deltaTime; if (subDivision > ropeMaxLength) subDivision = ropeMaxLength; - Rebuild(); + if (prevSubDivision - (int) subDivision >= 0) return; + + // Extend from start + rope.points.Insert(1, new Point(rope.points[1].position)); + rope.sticks.Clear(); + + // Ripple existing rope points + //for (int i = 2; i < (int) subDivision; i++) + //{ + // rope.points[i].position = rope.points[i + 1].position; + //} + + var builder = new RopeBuilder(rope.points, rope.sticks); + + // Re-gen sticks + for (int i = 0; i < (int)subDivision; i++) + { + //Debug.Log($"Reg-gen stick. from: {i} to {i + 1}, with dist: {distBetweenRopePoints}"); + builder.ConnectPointsWithDesiredLength(i, i + 1, distBetweenRopePoints); + } + rope = builder.Build(); + + RebuildRopeColliders(); + CreateOrderArray(); + } private void OnDestroy() @@ -150,7 +159,6 @@ public class RopeSimulator : MonoBehaviour private void Rebuild() { Debug.Log("rebuild"); - ropeCollidersParent.DestroyChildren(); RopeBuilder builder = new RopeBuilder(); builder.AddPoint(new Point(start.position, locked: true)); @@ -171,6 +179,14 @@ public class RopeSimulator : MonoBehaviour } rope = builder.Build(); + RebuildRopeColliders(); + + CreateOrderArray(); + } + + private void RebuildRopeColliders() + { + ropeCollidersParent.DestroyChildren(); foreach (var point in rope.points) { GameObject ropeCollider = new GameObject("Rope Collider"); @@ -184,12 +200,13 @@ public class RopeSimulator : MonoBehaviour var rigidBody = ropeCollider.AddComponent(); rigidBody.isKinematic = true; } - CreateOrderArray(); } private void Update() { - ShrinkenRope(1); + //Debug.Log($"overshoot: {rope.CalculateLengthOvershoot()}"); + //ShrinkenRope(1); + //ExtendRope(0); colliderToSquezeForce.Clear(); rope.points.First().position = start.position; @@ -300,7 +317,7 @@ public class RopeSimulator : MonoBehaviour Vector3 stickCentre = (stick.A.position + stick.B.position) / 2; Vector3 stickDir = (stick.A.position - stick.B.position).normalized; - float length = (stick.A.position - stick.B.position).magnitude; + float length = Vector2.Distance(stick.A.position, stick.B.position); if (length > stick.desiredLength || constrainStickMinLength) {