This commit is contained in:
Khauvinkh
2024-08-17 15:12:30 +02:00
2 changed files with 23 additions and 4 deletions

View File

@@ -14,19 +14,36 @@ public class SlidingCrane : MonoBehaviour
public float yRange = 10;
public float xRange = 5;
public Transform testTgt;
public Vector3 target;
void Start()
{
yMotion.AccelerateTo(1);
xMotion.AccelerateTo(1);
}
// Update is called once per frame
void Update()
{
target = testTgt.position;
Vector3 localTarget = transform.InverseTransformPoint(target);
xMotion.Update(Time.deltaTime);
yMotion.Update(Time.deltaTime);
Vector2 targetPlanar = new Vector2(localTarget.x, localTarget.z);
float xTgt = Mathf.InverseLerp(-xRange, xRange, targetPlanar.x);
Debug.Log(xTgt);
float yTgt = Mathf.InverseLerp(0, yRange, targetPlanar.y);
xMotion.AccelerateTo(xTgt);
yMotion.AccelerateTo(yTgt);
float x = Mathf.Lerp(-xRange, xRange, xMotion.progress);
float y = yMotion.progress * yRange;
yTransform.localPosition = new Vector3(0, 0, yMotion.progress * yRange);
xTransform.localPosition = new Vector3(xMotion.progress * xRange, 0, 0);
xTransform.localPosition = new Vector3(x, 0, 0);
}
}