๐ŸŽฎ 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;
}

image.png

Drift ์ฝ”๋“œ ์„ค๋ช…

๐ŸŽฏ ๋ณ€์ˆ˜ ์„ค๋ช…

๋ณ€์ˆ˜ ์„ค๋ช…
acceleration ์ „์ง„/ํ›„์ง„ ๊ฐ€์†๋„
steering ์กฐํ–ฅ ์†๋„
driftFactor ๋‚ฎ์„์ˆ˜๋ก ๋” ๋ฏธ๋„๋Ÿฌ์ง (0.85 ~ 0.95 ์ถ”์ฒœ)
maxSpeed ์ตœ๋Œ€ ์†๋„ ์ œํ•œ

๐ŸŽจ ๋“œ๋ฆฌํ”„ํŠธ ๋А๋‚Œ ์ปค์Šคํ„ฐ๋งˆ์ด์ง• ํŒ

โœ… Rigidbody2D์—์„œ ๋ฌผ๋ฆฌ ๊ฐ์† ๊ด€๋ จ ์„ค์ •

์„ค์ • ์ด๋ฆ„ ์—ญํ• 
Linear Damping ์ด๋™ ์†๋„์˜ ๊ฐ์† (๊ณต๊ธฐ ์ €ํ•ญ ๊ฐ™์€ ํšจ๊ณผ)
Angular Damping ํšŒ์ „ ์†๋„์˜ ๊ฐ์† (์ฐจ๊ฐ€ ๋น™๊ธ€๋น™๊ธ€ ๋„๋Š” ๊ฑธ ์ ์  ๋ฉˆ์ถ”๊ฒŒ)

๐ŸŽฏ ๋“œ๋ฆฌํ”„ํŠธ์— ์˜ํ–ฅ์„ ์ฃผ๋Š” ๊ฑด?

โœ… Linear Damping