๐ฎ Rigidbody2D ๊ธฐ๋ฐ ๋๋ฆฌํํธ ๊ตฌํ ์ฝ๋
- ๊ฐ์/๊ฐ์์ด ์์ฐ์ค๋ฝ๊ฒ ์ ์ฉ๋จ
- ํ์ ์ ๋ฏธ๋๋ฌ์ง์ด ๋ฐ์ (๋๋ฆฌํํธ)
- ํ์ด์ด๊ฐ ๋ฏธ๋๋ฌ์ง๋ฏ ์์ผ๋ก ์ฝ๊ฐ ๋ฐ๋ฆฌ๋ ํจ๊ณผ
[Header("์ ์ง/ํ์ง ๊ฐ์๋")] public float acceleration = 20f;
[Header("์กฐํฅ ์๋")] public float steering = 3f;
[Header("๋ฎ์์๋ก ๋ ๋ฏธ๋๋ฌ์ง")] public float driftFactor = 0.95f;
[Header("์ต๋ ์๋ ์ ํ")] public float maxSpeed = 10f;
private Rigidbody2D rb;
void Start()
{
rb = GetComponent<Rigidbody2D>();
}
void FixedUpdate()
{
float speed = Vector2.Dot(rb.linearVelocity, transform.up);
if (speed < maxSpeed)
{
rb.AddForce(transform.up * Input.GetAxis("Vertical") * acceleration);
}
// ์กฐํฅ ์
๋ ฅ
//float turnAmount = Input.GetAxis("Horizontal") * steering * speed * Time.fixedDeltaTime;
float turnAmount = Input.GetAxis("Horizontal") * steering * Mathf.Clamp(speed / maxSpeed, 0.4f, 1f);
rb.MoveRotation(rb.rotation - turnAmount); // Z์ถ ํ์
// ๋๋ฆฌํํธ ์ ์ฉ
ApplyDrift();
}
void ApplyDrift()
{
// ํ์ฌ ์๋๋ฅผ ์ฐจ์ฒด ๊ธฐ์ค์ผ๋ก ๋๋
Vector2 forwardVelocity = transform.up * Vector2.Dot(rb.linearVelocity, transform.up);
Vector2 sideVelocity = transform.right * Vector2.Dot(rb.linearVelocity, transform.right);
// ์์ผ๋ก ๋ฏธ๋๋ฌ์ง๋ ์๋๋ฅผ ์ค์ (๋ง์ฐฐ์ฒ๋ผ)
rb.linearVelocity = forwardVelocity + sideVelocity * driftFactor;
}

Drift ์ฝ๋ ์ค๋ช
๐ฏ ๋ณ์ ์ค๋ช
| ๋ณ์ |
์ค๋ช
|
acceleration |
์ ์ง/ํ์ง ๊ฐ์๋ |
steering |
์กฐํฅ ์๋ |
driftFactor |
๋ฎ์์๋ก ๋ ๋ฏธ๋๋ฌ์ง (0.85 ~ 0.95 ์ถ์ฒ) |
maxSpeed |
์ต๋ ์๋ ์ ํ |
๐จ ๋๋ฆฌํํธ ๋๋ ์ปค์คํฐ๋ง์ด์ง ํ
- ๋๋ฆฌํํธ๋ฅผ ๋ ๊ฐํ๊ฒ ํ๊ณ ์ถ์ผ๋ฉด โ
driftFactor ๊ฐ์ ๋ ๋ฎ์ถ์ธ์ (0.85 ์ ๋)
- ํ์ ์ด ๋๋ฌด ๋น ๋ฅด๋ฉด โ
steering ๊ฐ์ ์ค์ด์ธ์
- ์ฌ๋ผ์ด๋ฉ ๋๋ฌด ๋ง๋ค๋ฉด โ
acceleration์ ์ค์ด๊ฑฐ๋ driftFactor๋ฅผ ๋์ด์ธ์
โ
Rigidbody2D์์ ๋ฌผ๋ฆฌ ๊ฐ์ ๊ด๋ จ ์ค์
| ์ค์ ์ด๋ฆ |
์ญํ |
| Linear Damping |
์ด๋ ์๋์ ๊ฐ์ (๊ณต๊ธฐ ์ ํญ ๊ฐ์ ํจ๊ณผ) |
| Angular Damping |
ํ์ ์๋์ ๊ฐ์ (์ฐจ๊ฐ ๋น๊ธ๋น๊ธ ๋๋ ๊ฑธ ์ ์ ๋ฉ์ถ๊ฒ) |
๐ฏ ๋๋ฆฌํํธ์ ์ํฅ์ ์ฃผ๋ ๊ฑด?
โ
Linear Damping
- ๋๋ฆฌํํธ๊ฐ ๋๋ฌด ์ค๋ ์ง์๋๋ฉด ์ด๊ฑธ
0.5 ~ 2 ์ ๋๋ก ์ฌ๋ ค์ค