mirror of
https://projects.caleb-brown.dev/UDRI-XRT/UDRIGEEKCup2024.git
synced 2025-01-22 07:08:51 -05:00
Fixed positioning
This commit is contained in:
parent
76e38e91f0
commit
8e5ca9b248
@ -34,7 +34,7 @@ public class MoveAndReturn : MonoBehaviour
|
|||||||
private void Start()
|
private void Start()
|
||||||
{
|
{
|
||||||
// Save the starting position of the object
|
// Save the starting position of the object
|
||||||
startingPosition = transform.position;
|
startingPosition = transform.localPosition;
|
||||||
|
|
||||||
// Calculate the target position based on the selected axis and distance
|
// Calculate the target position based on the selected axis and distance
|
||||||
switch (axisOfMovement)
|
switch (axisOfMovement)
|
||||||
@ -53,7 +53,6 @@ public class MoveAndReturn : MonoBehaviour
|
|||||||
// Start the movement coroutine
|
// Start the movement coroutine
|
||||||
StartCoroutine(MoveObject());
|
StartCoroutine(MoveObject());
|
||||||
}
|
}
|
||||||
|
|
||||||
private IEnumerator MoveObject()
|
private IEnumerator MoveObject()
|
||||||
{
|
{
|
||||||
while (true)
|
while (true)
|
||||||
@ -61,19 +60,19 @@ public class MoveAndReturn : MonoBehaviour
|
|||||||
// Move the object towards the target position
|
// Move the object towards the target position
|
||||||
if (movingForward)
|
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 the object reaches the target position, start moving back
|
||||||
if (transform.position == targetPosition)
|
if (transform.localPosition == targetPosition)
|
||||||
movingForward = false;
|
movingForward = false;
|
||||||
}
|
}
|
||||||
// Move the object back to the starting position
|
// Move the object back to the starting position
|
||||||
else
|
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 the object reaches the starting position, start moving forward again
|
||||||
if (transform.position == startingPosition)
|
if (transform.localPosition == startingPosition)
|
||||||
{
|
{
|
||||||
movingForward = true;
|
movingForward = true;
|
||||||
cyclesCompleted++;
|
cyclesCompleted++;
|
||||||
@ -87,7 +86,6 @@ public class MoveAndReturn : MonoBehaviour
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
yield return null; // Wait for the next frame
|
yield return null; // Wait for the next frame
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user