주인공을 따라다니는 카메라

|


슈퍼마리오의 카메라 처럼 일정 거리에서는 카메라가 움직이지 않고 일정거리를 넘어갔을때만 카메라가 이동함.


// If the player has moved beyond the x margin...

if(CheckXMargin())

// ... the target x coordinate should be a Lerp between the camera's current x position and the player's current x position.

targetX = Mathf.Lerp(transform.position.x, player.position.x, xSmooth * Time.deltaTime);


// If the player has moved beyond the y margin...

if(CheckYMargin())

// ... the target y coordinate should be a Lerp between the camera's current y position and the player's current y position.

targetY = Mathf.Lerp(transform.position.y, player.position.y, ySmooth * Time.deltaTime);


-> 마진 체크 후 카메라 이동


->Lerp 가 결국에는 targetY에 대입이 되며 targetY값은 계속 증가 결국 플레이어의 위치값과 똑같아짐









// The target x and y coordinates should not be larger than the maximum or smaller than the minimum.

targetX = Mathf.Clamp(targetX, minXAndY.x, maxXAndY.x);

targetY = Mathf.Clamp(targetY, minXAndY.y, maxXAndY.y);


// Set the camera's position to the target position with the same z component.

transform.position = new Vector3(targetX, targetY, transform.position.z);


-> 카메라 최대 거리 제한






결국엔 히어로의 값이랑 메인카메라랑 값이 똑같아 져야 되지만 카메라의 위치를 제한을 둬서 일정거리까지는 이동을 하지 못함








Trackback 0 And Comment 0
prev | 1 | ··· | 7 | 8 | 9 | 10 | 11 | 12 | 13 | next