Crane logic fixes

This commit is contained in:
nothke 2024-08-17 16:29:47 +02:00
parent b2d8ac944c
commit 41ed2e559f
3 changed files with 13 additions and 5 deletions

View File

@ -1174,7 +1174,7 @@ MonoBehaviour:
m_Script: {fileID: 11500000, guid: b236863c86ffb73498f0262aaf900afd, type: 3} m_Script: {fileID: 11500000, guid: b236863c86ffb73498f0262aaf900afd, type: 3}
m_Name: m_Name:
m_EditorClassIdentifier: m_EditorClassIdentifier:
strength: 100 strength: 50
--- !u!135 &1711954335 --- !u!135 &1711954335
SphereCollider: SphereCollider:
m_ObjectHideFlags: 0 m_ObjectHideFlags: 0
@ -1194,7 +1194,7 @@ SphereCollider:
m_ProvidesContacts: 0 m_ProvidesContacts: 0
m_Enabled: 1 m_Enabled: 1
serializedVersion: 3 serializedVersion: 3
m_Radius: 5.264741 m_Radius: 8.713587
m_Center: {x: 0, y: 0, z: 0} m_Center: {x: 0, y: 0, z: 0}
--- !u!1 &1757469719 --- !u!1 &1757469719
GameObject: GameObject:

View File

@ -52,7 +52,7 @@ public class CranePickDrop : MonoBehaviour
magnet.strength = magnetStrength; magnet.strength = magnetStrength;
crane.testTgt = handlingBody.transform; crane.testTgt = handlingBody.transform;
if (Vector3.Distance(handlingBody.position, magnet.transform.position) < 1f) if (magnet.IsCloseTo(handlingBody, 2f))
{ {
crane.testTgt = dropTarget; crane.testTgt = dropTarget;
state = State.Tansporting; state = State.Tansporting;

View File

@ -17,14 +17,19 @@ public class SlidingCrane : MonoBehaviour
public Transform testTgt; public Transform testTgt;
public Vector3 target; public Vector3 target;
private void Start()
{
target = transform.position;
}
void Update() void Update()
{ {
if (testTgt) if (testTgt)
target = testTgt.position; target = testTgt.position;
Vector3 localTarget = transform.InverseTransformPoint(target); Vector3 localTarget = transform.InverseTransformPoint(target);
xMotion.Update(Time.deltaTime);
yMotion.Update(Time.deltaTime);
Vector2 targetPlanar = new Vector2(localTarget.x, localTarget.z); 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 x = Mathf.Lerp(-xRange, xRange, xMotion.progress);
float y = yMotion.progress * yRange; float y = yMotion.progress * yRange;
xMotion.Update(Time.deltaTime);
yMotion.Update(Time.deltaTime);
yTransform.localPosition = new Vector3(0, 0, yMotion.progress * yRange); yTransform.localPosition = new Vector3(0, 0, yMotion.progress * yRange);
xTransform.localPosition = new Vector3(x, 0, 0); xTransform.localPosition = new Vector3(x, 0, 0);
} }