mirror of
https://github.com/nothke/quality-control.git
synced 2025-08-31 07:43:42 +00:00
Sliding crane with height
This commit is contained in:
@@ -7,33 +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;
|
||||
|
||||
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;
|
||||
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;
|
||||
if (targetTransform)
|
||||
targetPoint = targetTransform.position;
|
||||
|
||||
|
||||
Vector3 localTarget = transform.InverseTransformPoint(target);
|
||||
Vector3 localTarget = transform.InverseTransformPoint(targetPoint);
|
||||
|
||||
Vector2 targetPlanar = new Vector2(localTarget.x, localTarget.z);
|
||||
|
||||
@@ -48,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);
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user