1
0
mirror of https://projects.caleb-brown.dev/UDRI-XRT/UDRIGEEKCup2024.git synced 2025-01-21 22:58:50 -05:00

Fixed positioning

This commit is contained in:
Ktaylor 2024-04-24 09:10:37 -04:00
parent 76e38e91f0
commit 8e5ca9b248

View File

@ -34,7 +34,7 @@ public class MoveAndReturn : MonoBehaviour
private void Start()
{
// Save the starting position of the object
startingPosition = transform.position;
startingPosition = transform.localPosition;
// Calculate the target position based on the selected axis and distance
switch (axisOfMovement)
@ -53,7 +53,6 @@ public class MoveAndReturn : MonoBehaviour
// Start the movement coroutine
StartCoroutine(MoveObject());
}
private IEnumerator MoveObject()
{
while (true)
@ -61,19 +60,19 @@ public class MoveAndReturn : MonoBehaviour
// Move the object towards the target position
if (movingForward)
{
transform.position = Vector3.MoveTowards(transform.position, targetPosition, speed * Time.deltaTime);
transform.localPosition = Vector3.MoveTowards(transform.localPosition, targetPosition, speed * Time.deltaTime);
// If the object reaches the target position, start moving back
if (transform.position == targetPosition)
if (transform.localPosition == targetPosition)
movingForward = false;
}
// Move the object back to the starting position
else
{
transform.position = Vector3.MoveTowards(transform.position, startingPosition, speed * Time.deltaTime);
transform.localPosition = Vector3.MoveTowards(transform.localPosition, startingPosition, speed * Time.deltaTime);
// If the object reaches the starting position, start moving forward again
if (transform.position == startingPosition)
if (transform.localPosition == startingPosition)
{
movingForward = true;
cyclesCompleted++;
@ -87,7 +86,6 @@ public class MoveAndReturn : MonoBehaviour
}
}
}
yield return null; // Wait for the next frame
}
}