Edited Thread-Title to be more search-friendly
Meh, I’m giving up -.- Tried to fix this for hours now but I’m just too blind to see it…
I have two charas (Wasch and Lucat) and one camera.
One waypoint in each head (camPositionWasch/Lucat) and one behind each head (camPathPointWasch/Lucat).
The cam sits in one camPosition, should move to the first PathPoint, then to the second, last to the new camPosition.
What I have is that it moves smoothly to the first PathPoint, then jumps to the new camPosition
private var camPathPointWasch;
private var camPathPointLucat;
private var camPositionWasch;
private var camPositionLucat;
private var lerpSpeed = 0.5;
private var firstPointReached : boolean = false;
private var secondPointReached : boolean = false;
private var lastPointReached : boolean = false;
function Awake ()
{
camPathPointWasch = gameObject.Find("CamPathPointWasch").transform;
camPathPointLucat = gameObject.Find("CamPathPointLucat").transform;
camPositionWasch = gameObject.Find("CamPositionWasch").transform;
camPositionLucat = gameObject.Find("CamPositionLucat").transform;
}
function LucatToWasch ()
{
Debug.Log("LucatToWasch started");
while ( !lastPointReached )
{
transform.parent = camPathPointLucat;
//as long as first waypoint hasn't been reached yet,
//lerp Camera towards it and make it face in the same direction
while ( !firstPointReached)
{
Debug.Log("First Point not reached yet");
Debug.Log("before Lerp");
Debug.Log(transform.localPosition);
transform.position = Vector3.Lerp
(camPositionLucat.position, camPathPointLucat.position, Time.time * lerpSpeed);
Debug.Log("after Lerp");
Debug.Log(transform.localPosition);
transform.rotation = Quaternion.Lerp
(camPositionLucat.rotation, camPathPointLucat.rotation, Time.time * lerpSpeed);
if (transform.position == camPathPointLucat.position)
{
Debug.Log("first Waypoint reached");
firstPointReached = true;
}
yield;
}
transform.parent = camPathPointWasch;
//as long as second waypoint hasn't been reached yet,
// lerp Camera towards it and make it face in the same direction
while ( !secondPointReached)
{
Debug.Log("Second Point not reached yet");
Debug.Log("before Lerp");
Debug.Log(transform.localPosition);
transform.position = Vector3.Lerp
(camPathPointLucat.position, camPathPointWasch.position, Time.time * lerpSpeed);
Debug.Log("after Lerp");
Debug.Log(transform.localPosition);
transform.rotation = Quaternion.Lerp
(camPathPointLucat.rotation, camPathPointWasch.rotation, Time.time * lerpSpeed);
if (transform.position == camPathPointWasch.position)
{
Debug.Log("second Waypoint reached");
secondPointReached = true;
}
yield;
}
transform.parent = camPositionWasch;
//as long as last waypoint hasn't been reached yet,
//lerp Camera towards it and make it face in the same direction
while ( !lastPointReached)
{
Debug.Log("Third Point not reached yet");
Debug.Log("before Lerp");
Debug.Log(transform.localPosition);
transform.position = Vector3.Lerp
(camPathPointWasch.position, camPositionWasch.position, Time.time * lerpSpeed);
Debug.Log("after Lerp");
Debug.Log(transform.localPosition);
transform.rotation = Quaternion.Lerp
(camPathPointWasch.rotation, camPositionWasch.rotation, Time.time * lerpSpeed);
if (transform.position == camPositionWasch.position)
{
Debug.Log("third Waypoint reached");
lastPointReached = true;
}
yield;
}
yield;
}
firstPointReached = false;
secondPointReached = false;
lastPointReached = false;
transform.position = camPositionWasch.position;
transform.rotation = camPositionWasch.rotation;
transform.parent = camPositionWasch;
}
Debug.Log shows, that the first lerp-loop get’s executed nicely with repeated calls, until the first Waypoint is reached.
The second is entered once but that same call already reaches secondWaypoint.
The same happens for the third loop.
I’m all out of ideas :?
Greetz, Ky.
Edit
Out of curiosity I tried
if (firstPointReached secondPointReached lastPointReached)
{
firstPointReached = false;
secondPointReached = false;
lastPointReached = false;
}
then no lerping happend anymore at all. (Each loop entered once and left right away)
But the strange thing: after commenting the if-clause out again, it didn’t return to lerping to the first waypoint! Oo Only after a restart of unity it returned to the behaviour described above…
This is so fishy