mirror of
https://github.com/nothke/quality-control.git
synced 2025-08-08 23:03:43 +00:00
Sliding crane can track world targets
This commit is contained in:
@@ -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);
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user