์ฝ”๋“œ๋„ ๊ฐ™์ด ์˜ฌ๋ ค๋ด„


์šฐ์„  void Update()์— ์žˆ๋Š” ์ž…๋ ฅ ๋ฐ›์•„์ฃผ๋Š” ์ฝ”๋“œ

xInput = Input.GetAxisRaw("Horizontal");

yInput = Input.GetKeyDown(KeyCode.Space);

yOutput = Input.GetKeyUp(KeyCode.Space);


์ด๊ฑด ์ ํ”„ ๋ฒ„ํผ ์นด์šดํŠธ ์ฝ”๋“œ (์–˜๋„ update์— ์žˆ์Œ)

ย  ย  ย  ย  if (grounded)

ย  ย  ย  ย  {

ย  ย  ย  ย  ย  ย  hangCounter = hangTime

ย  ย  ย  ย  }

ย  ย  ย  ย  else

ย  ย  ย  ย  {

ย  ย  ย  ย  ย  ย  hangCounter -= Time.fixedDeltaTime;

ย  ย  ย  ย  }


ย  ย  ย  ย  if (yInput && grounded)

ย  ย  ย  ย  {

ย  ย  ย  ย  ย  ย  jumpBufferCounter = jumpBufferTime;

ย  ย  ย  ย  }

ย  ย  ย  ย  else

ย  ย  ย  ย  {

ย  ย  ย  ย  ย  ย  jumpBufferCounter -= Time.fixedDeltaTime;

ย  ย  ย  ย  }





์ด๊ฑด void FixedUpdate()์— ์žˆ๋Š” ์ขŒ์šฐ ์ด๋™ ์ฝ”๋“œ
float currentVelocityX = rb.velocity.x;

if (xInput != 0)
{
currentVelocityX = Mathf.MoveTowards(currentVelocityX, moveSpeed * xInput, acceleration * Time.deltaTime);
}
else
{
currentVelocityX = Mathf.MoveTowards(currentVelocityX, 0f, deceleration * Time.deltaTime);
}

currentVelocityX = Mathf.Clamp(currentVelocityX, -maxSpeed, maxSpeed);

lastVelocityX = currentVelocityX;

rb.velocity = new Vector2(currentVelocityX, rb.velocity.y);


์ด๊ฒŒ ๊ทธ ๋ฐ‘์— ์žˆ๋Š” ์ ํ”„ ์‹คํ–‰ ์ฝ”๋“œ

if (jumpBufferCounter > 0 && hangCounter > 0f)

{

rb.velocity = new Vector2(rb.velocity.x, jumpForce);


jumpBufferCounter = 0;

hangCounter = 0f;

}


if (yOutput && rb.velocity.y > 0)

{

rb.velocity = new Vector2(rb.velocity.x, rb.velocity.y * 0.2f);

}




์ผ๋‹จ ์—๋””ํ„ฐ์—์„œ์˜ ์›€์ง์ž„๊ณผ ๋นŒ๋“œํ•˜๊ณ  ๋‚˜์„œ์˜ ์›€์ง์ž„์ด ๋‹ค๋ฅด๋‹ค๋Š” ๊ฒŒ ๋ฌธ์ œ


๊ทผ๋ฐ ๊ณ„์† ํ•ด๋ณด๋‹ˆ๊นŒ ํŠน์ดํ•œ ์ ์ด ์ขŒ์šฐ ์›€์ง์ž„ ์†๋„๋Š” ์ •ํ™•ํžˆ ๊ฐ™์€๋ฐ ์ ํ”„ ๋†’์ด๋งŒ ๋‹ค๋ฆ„ (์ ํ”„ ๋†’์ด ๋ง๊ณ ๋Š” ๋‹ค๋ฅธ ์ ์ด ํ•˜๋‚˜๋„ ์—†์Œ)


์—๋””ํ„ฐ์—์„œ ์ ํ”„ํ•  ๋•Œ ๋ณด๋‹ค ๋นŒ๋“œ exe์—์„œ ์ ํ”„ํ•  ๋•Œ ๋†’์ด ์˜ฌ๋ผ๊ฐ


ํ”„๋กœ์ ํŠธ ์ค‘๋ ฅ ๊ณ„์ˆ˜๊ฐ€ ๋‹ฌ๋ผ์ง€๋‚˜ ์‹ถ์–ด์„œ gravity y๊ฐ’ -9.81๋กœ ์žก์•„์ฃผ๋Š” ๋ณ€์ˆ˜ ์„ ์–ธ๋„ void Start()์— ๋„ฃ์–ด๋ดค๋Š”๋ฐ ๋‹ฌ๋ผ์ง„ ๊ฑฐ ์—†์Œ


Gravity Scale์€ 8, jumpForce๋Š” 33์ž„


์ œ๋ฐœ ์‚ด๋ ค์ค˜ ์ •์‹  ๋‚˜๊ฐˆ ๊ฒƒใ„ฑ ใ…ใ…Œใ…‡์•„ ์ง„์งœใ„นใ…Ž