# Conflicts:
#	Assets/Scripts/SlidingCrane.cs
This commit is contained in:
Daniel Tyomin
2024-08-19 23:52:39 +02:00
10 changed files with 1289 additions and 125 deletions

View File

@@ -18,6 +18,7 @@ public class CranePickDrop : MonoBehaviour
Catching,
WaitingToCatch,
Tansporting,
WaitBeforeDrop,
Finished,
}
@@ -37,7 +38,7 @@ public class CranePickDrop : MonoBehaviour
if (otherRb && otherRb.isKinematic == false && state == State.Idle)
{
handlingBody = otherRb;
crane.testTgt = handlingBody.transform;
crane.targetTransform = handlingBody.transform;
state = State.Catching;
}
}
@@ -50,6 +51,7 @@ public class CranePickDrop : MonoBehaviour
void Start()
{
magnetStrength = magnet.strength;
crane.heightMotion.AccelerateTo(1);
}
void Update()
@@ -64,6 +66,11 @@ public class CranePickDrop : MonoBehaviour
return;
}
if (magnet.IsCloseToPlanar(handlingBody, 10f))
{
crane.heightMotion.AccelerateTo(0);
}
if (magnet.IsCloseTo(handlingBody, 5f))
{
magnet.strength = magnetStrength;
@@ -71,7 +78,7 @@ public class CranePickDrop : MonoBehaviour
if (magnet.IsCloseTo(handlingBody, 2f))
{
crane.testTgt = null;
crane.targetTransform = null;
state = State.WaitingToCatch;
timer = 3;
@@ -84,16 +91,33 @@ public class CranePickDrop : MonoBehaviour
if (timer < 0)
{
state = State.Tansporting;
crane.testTgt = dropTarget;
crane.targetTransform = dropTarget;
crane.heightMotion.AccelerateTo(1);
}
}
else if (state == State.Tansporting)
{
if (magnet.IsCloseToPlanar(dropTarget))
if (magnet.IsCloseToPlanar(dropTarget, 10f))
{
crane.heightMotion.AccelerateTo(0);
}
if (magnet.IsCloseToPlanar(dropTarget, 3f))
{
state = State.WaitBeforeDrop;
timer = 3;
}
}
else if (state == State.WaitBeforeDrop)
{
timer -= Time.deltaTime;
if (timer < 0)
{
magnet.strength = 0;
state = State.Idle;
crane.heightMotion.AccelerateTo(1);
}
}
}

View File

@@ -0,0 +1,20 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using Nothke.Interaction;
using Nothke.Interaction.Items;
public class SetItemsOnStart : MonoBehaviour
{
public Hands hands;
public GenericItem[] items;
void Start()
{
foreach (var item in items)
{
hands.Take(item);
}
}
}

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: bb13478e4c42bd7489db482354f8b915
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -7,34 +7,55 @@ public class SlidingCrane : MonoBehaviour
{
public InertialInterpolator xMotion = InertialInterpolator.Default();
public InertialInterpolator yMotion = InertialInterpolator.Default();
public InertialInterpolator heightMotion = InertialInterpolator.Default();
public Transform xTransform;
public Transform yTransform;
public float yRange = 10;
public float xRange = 5;
public float heightRange = 10;
[Range(0f, 1f)]
public float xStart = 0.5f;
public Transform testTgt;
public Vector3 target;
public float heightMax = -0.7f;
public float heightMin = -10;
/// <summary>
/// if targetTrasnform is set, it will go to it. If null it will go to targetPoint
/// </summary>
public Transform targetTransform;
/// <summary>
/// if targetTrasnform is set, it will go to it. If null it will go to targetPoint
/// </summary>
public Vector3 targetPoint;
public Transform cradleTransform;
public Rigidbody cradleRb;
private void Start()
{
target = transform.position;
xMotion.progress = xStart;
targetPoint = transform.position;
xMotion.progress = 0.5f;
}
private void Update()
{
if (Input.GetKeyDown(KeyCode.V))
heightMotion.AccelerateTo(0);
if (Input.GetKeyDown(KeyCode.F))
heightMotion.AccelerateTo(1);
}
void FixedUpdate()
{
if (testTgt)
target = testTgt.position;
Vector3 localTarget = transform.InverseTransformPoint(target);
if (targetTransform)
targetPoint = targetTransform.position;
Vector3 localTarget = transform.InverseTransformPoint(targetPoint);
Vector2 targetPlanar = new Vector2(localTarget.x, localTarget.z);
@@ -49,10 +70,13 @@ public class SlidingCrane : MonoBehaviour
xMotion.Update(Time.deltaTime);
yMotion.Update(Time.deltaTime);
heightMotion.Update(Time.deltaTime);
yTransform.localPosition = new Vector3(0, 0, yMotion.progress * yRange);
xTransform.localPosition = new Vector3(x, 0, 0);
//cradleRb.MovePosition(cradleTransform.position);
cradleRb.transform.localPosition = new Vector3(0, Mathf.Lerp(heightMin, heightMax, heightMotion.progress), 0);
}
}