public class CameraController : MonoBehaviour
{
public Transform target;

public float smoothSpeed = 0.2f;

private void LateUpdate()
{
Vector3 pos = Vector3.Lerp(transform.position, target.position, smoothSpeed);
transform.position = new Vector3(pos.x, pos.y, -10);
}

}




public class PlayerController : MonoBehaviour
{
public float moveSpeed = 1000f;
private Rigidbody2D rb;
private Vector2 inputVec;

// Start is called before the first frame update
private void Start()
{
rb = GetComponent<Rigidbody2D>();
inputVec = new Vector2();
}

private void Update()
{
inputVec.x = Input.GetAxis("Horizontal");
inputVec.y = Input.GetAxis("Vertical");
rb.velocity = inputVec * moveSpeed;
}
}



์ด๋ ‡๊ฒŒ ํ–ˆ๋Š”๋ฐ ์›€์ง์ž„์— ์ž”์ƒ์ด ๋‚จ๊ณ  ๋ถ€๋“ค๋ถ€๋“ค ๋–จ๋ฆฌ๋Š” ๊ฒƒ ๊ฐ™์€ ๋А๋‚Œ์ด ๋‚˜.

๋ญ๊ฐ€ ๋ฌธ์ œ์ž„? ์บ๋ฆญํ„ฐ์—๋Š” rigidbody2d๋ž‘ boxcollider2d ๋„ฃ์–ด์คฌ์–ด


์นด๋ฉ”๋ผ ์Šคํฌ๋ฆฝํŠธ ์—†์• ๋ฉด ๋ฌธ์ œ๊ฐ€ ์—†์–ด์ง. ๊ทธ๋Ÿฐ๋ฐ ์นด๋ฉ”๋ผ๊ฐ€ ํ”๋“ค๋ฆฐ๋‹ค๋˜๊ฐ€ ํ•˜๋Š”๊ฑฐ๋ผ๋ฉด ์บ๋ฆญํ„ฐ๋ž‘ ๋ฐฐ๊ฒฝ์ด ๊ฐ™์ด ์ž”์ƒ์ด ๋‚จ์•„์•ผ ํ•˜๋Š”๋ฐ ๋ฐฐ๊ฒฝ์€ ์•ˆ๋‚จ๊ณ  ์บ๋ฆญํ„ฐ๋งŒ ์ž”์ƒ์ด ๋‚จ์Œ.


rigidbody2d์˜ interpolate๋ฅผ interpolate๋‚˜ extrapolate๋กœ ํ•˜๋ฉด ์ž”์ƒ์ด ์ข€ ์ค„์–ด๋“ค์–ด