From 41ed2e559f0452249fb931de311472a6641a56ee Mon Sep 17 00:00:00 2001 From: nothke Date: Sat, 17 Aug 2024 16:29:47 +0200 Subject: [PATCH] Crane logic fixes --- Assets/Scenes/test_conveyor_belt_character.unity | 4 ++-- Assets/Scripts/CranePickDrop.cs | 2 +- Assets/Scripts/SlidingCrane.cs | 12 ++++++++++-- 3 files changed, 13 insertions(+), 5 deletions(-) diff --git a/Assets/Scenes/test_conveyor_belt_character.unity b/Assets/Scenes/test_conveyor_belt_character.unity index 4f6b4ba..f934439 100644 --- a/Assets/Scenes/test_conveyor_belt_character.unity +++ b/Assets/Scenes/test_conveyor_belt_character.unity @@ -1174,7 +1174,7 @@ MonoBehaviour: m_Script: {fileID: 11500000, guid: b236863c86ffb73498f0262aaf900afd, type: 3} m_Name: m_EditorClassIdentifier: - strength: 100 + strength: 50 --- !u!135 &1711954335 SphereCollider: m_ObjectHideFlags: 0 @@ -1194,7 +1194,7 @@ SphereCollider: m_ProvidesContacts: 0 m_Enabled: 1 serializedVersion: 3 - m_Radius: 5.264741 + m_Radius: 8.713587 m_Center: {x: 0, y: 0, z: 0} --- !u!1 &1757469719 GameObject: diff --git a/Assets/Scripts/CranePickDrop.cs b/Assets/Scripts/CranePickDrop.cs index a5bae21..ae66884 100644 --- a/Assets/Scripts/CranePickDrop.cs +++ b/Assets/Scripts/CranePickDrop.cs @@ -52,7 +52,7 @@ public class CranePickDrop : MonoBehaviour magnet.strength = magnetStrength; crane.testTgt = handlingBody.transform; - if (Vector3.Distance(handlingBody.position, magnet.transform.position) < 1f) + if (magnet.IsCloseTo(handlingBody, 2f)) { crane.testTgt = dropTarget; state = State.Tansporting; diff --git a/Assets/Scripts/SlidingCrane.cs b/Assets/Scripts/SlidingCrane.cs index c69aa4d..b4312c3 100644 --- a/Assets/Scripts/SlidingCrane.cs +++ b/Assets/Scripts/SlidingCrane.cs @@ -17,14 +17,19 @@ public class SlidingCrane : MonoBehaviour public Transform testTgt; public Vector3 target; + private void Start() + { + target = transform.position; + } + void Update() { if (testTgt) target = testTgt.position; + Vector3 localTarget = transform.InverseTransformPoint(target); - xMotion.Update(Time.deltaTime); - yMotion.Update(Time.deltaTime); + Vector2 targetPlanar = new Vector2(localTarget.x, localTarget.z); @@ -37,6 +42,9 @@ public class SlidingCrane : MonoBehaviour float x = Mathf.Lerp(-xRange, xRange, xMotion.progress); float y = yMotion.progress * yRange; + xMotion.Update(Time.deltaTime); + yMotion.Update(Time.deltaTime); + yTransform.localPosition = new Vector3(0, 0, yMotion.progress * yRange); xTransform.localPosition = new Vector3(x, 0, 0); }