Game Development Reference
In-Depth Information
break;
case PlayerStateController.playerStates.right:
trackPlayer();
break;
}
}
void trackPlayer()
{
// Get and store the current camera position, and the current
// player position, in world coordinates
Vector3currCamPos = transform.position;
Vector3currPlayerPos = playerObject.transform.position;
if(currCamPos.x == currPlayerPos.x&&currCamPos.y ==
currPlayerPos.y)
{
// Positions are the same - tell the camera not to move, then abort.
currLerpDistance = 1f;
lastTargetPosition = currCamPos;
currTargetPosition = currCamPos;
return;
}
// Reset the travel distance for the lerp
currLerpDistance = 0f;
// Store the current target position so we can lerp from it
lastTargetPosition = currCamPos;
// Store the new target position
currTargetPosition = currPlayerPos;
// Change the Z position of the target to the same as the current.
//We don' want that to change.
currTargetPosition.z = currCamPos.z;
}
void stopTrackingPlayer()
{
// Set the target positioning to the camera's current position
// to stop its movement in its tracks
Vector3 currCamPos = transform.position;
 
Search WWH ::




Custom Search