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๋ก ํ๋ฉด ์์์ด ์ข ์ค์ด๋ค์ด
๋ ์ดํธ์ ๋๋๋ฌธ์ธ๋ฏ
๊ทธ๋ฅ update๋ก ๋ฐ๊ฟ๋ ๊ทธ๋๋ก ์์์ด ๋จ์. ์นด๋ฉ๋ผ ์คํฌ๋ฆฝํธ ์์ ๋ฉด ์์ ์๋จ๋ ๊ฑฐ ๋ณด๋ฉด ์นด๋ฉ๋ผ์ชฝ ๋ฌธ์ ๋ ๋ง๋ ๊ฒ ๊ฐ์๋ฐ...
์นด๋ฉ๋ผ๋ fixedupdate๋ก ํ๋ฉด ํด๊ฒฐ๋๋ค? ์์ด๋ฐ๊ฑฐ์ง?
์บ๋ฆญํฐ ์ปจํธ๋กค๋ฌ์ ์๋ ๋ฆฌ์ง๋ฐ๋๋์บ๋ฆญ์ ๋ถ์ด์๋ ์ค๋ธ์ ํธ์ ๊ฐ์ฒด๋ ์ถฉ๋๋๊ณ ์์๋ฏ
LateUpdate๋ฅผ FixedUpdate๋ก ๋ณ๊ฒฝ
์ด ์ด๋ ๊ฒํ๋๊น ํด๊ฒฐ๋์ด. ์๊ทธ๋ฐ๊ฑฐ์ผ?
๋ฆฌ์ง๋๋ฐ๋์ ์๋๋ก ์์ง์ด๋๊น ์๋๊ณต๊ฐ ์ด๋์ด ์๋ ๋ฌผ๋ฆฌ๊ณต๊ฐ ์ด๋์. ๊ทธ๋์ ๋ฌผ๋ฆฌ ์์น๊ฐ ์ฐ์ฐ๋๋ FixedUpdate๋ก ์นด๋ฉ๋ผ ๋ก์ง์ ์ด๋์์ผ์ ์ฑํฌ๋ฅผ ๋ง์ถ๊ฒ๋๋ค
์ํ ์ค๋ช ๊น์ง ํด์ค์ ์ ๋ง ๊ณ ๋ง์!!
์บ๋ฆญํฐ ์์ง์ด๋๊ฑธ FixedUpdate๋ฅผ ์ฌ์ฉํ์์ค