Unity Character Controller ์‚ฌ์šฉํ•˜๊ธฐ

1 ๋ถ„ ์†Œ์š”

๐Ÿ’ก navmesh ๋งŒ์„ ์‚ฌ์šฉํ•˜๋‹ค chacter controller์™€ ํ˜ผ์šฉ ์‚ฌ์šฉํ•˜๋ ค๊ณ  ์•Œ์•„๋ณด์•˜๋‹ค.

Character Controller ๋ž€

์œ ๋‹ˆํ‹ฐ์—์„œ ์ง€์›ํ•˜๋Š” ์ปดํฌ๋„ŒํŠธ๋กœ ์ฃผ๋กœ ์‚ฌ๋žŒ ํ˜•ํƒœ์˜ ์บ๋ฆญํ„ฐ ์›€์ง์ž„๊ณผ ๊ด€๋ จ๋œ ์ œ์–ด๋ฅผ ์œ„ํ•ด ์‚ฌ์šฉํ•จ

  • capsule ํ˜•ํƒœ์˜ collider๊ฐ€ ํฌํ•จ์ด ๋˜์–ด์žˆ์–ด ๋ณ„๋„์˜ collider๊ฐ€ ํ•„์š”์—†์Œ
  • ์˜ฌ๋ผ๊ฐˆ ์ˆ˜ ์žˆ๋Š” ๊ฒฝ์‚ฌ ๋†’์ด, ๊ณ„๋‹จ, ๋“ฑ์— ๋Œ€ํ•œ ์„ค์ •๋„ ๊ฐ€๋Šฅ
  • collider ๋ฒ”์œ„ ์„ค์ • ๊ฐ€๋Šฅ

์บ๋ฆญํ„ฐ ์›€์ง์ด๋Š” ๋ฐฉ๋ฒ•

  1. ChacterController ์ปดํฌ๋„ŒํŠธ๋ฅผ ๊ฐ€์ ธ์˜จ๋‹ค.
  2. move ํ•จ์ˆ˜๋กœ ์›€์ง์ธ๋‹ค. ex) Move(direction * speed * Time.deltaTime);
  3. rigidy body๋ฅผ ์‚ฌ์šฉํ•˜์ง€ ์•Š๊ธฐ ๋•Œ๋ฌธ์— ์ค‘๋ ฅ์— ๋Œ€ํ•œ ์ฒ˜๋ฆฌ๋„ย ํ•ด์ค˜์•ผํ•œ๋‹ค. ์•„๋ž˜ (isGrounded ๋ถ€๋ถ„)
CharacterController controller = go.GetComponent<CharacterController>();

Vector3 direction = new Vector3(1, 0, 1);
float speed = 5;
if (controller.isGrounded == false)
{
    direction.y += 9.8f * Time.deltaTime;
}

controller.Move(direction * speed * Time.deltaTime);

Hpbar ์ฒด๋ ฅ์— ๋”ฐ๋ผ ์ด๋ฏธ์ง€ ์‚ฌ์ด์ฆˆ ์กฐ์ ˆ

  1. ์œ„ ๋™์˜์ƒ์—์„œ ์ œ์ž‘ํ•œ hpbar๋ฅผ ๊ธฐ์ค€์œผ๋กœ ์ž‘์—…ํ–ˆ๋‹ค
  2. hpbar์˜ ์ด๋ฏธ์ง€์˜ scale์„ ์ฒด๋ ฅ์˜ ๋น„์œจ์—(current/max) ๋”ฐ๋ผ ์กฐ์ ˆ
  3. ์ด๋ฏธ์ง€์˜ ํ”ผ๋ฒ—๋“ฑ์˜ ์…‹ํŒ…์€ ์—ฌ๊ธฐ๋ฅผ ์ฐธ์กฐ ํ–ˆ๋‹ค.
public class HpBar : MonoBehaviour
{
    public GameObject innerBar;
    public void updateHpbar(Vector3 pos, float current, float max)
    {
        transform.position = pos;
        innerBar.transform.localScale = new Vector3(current / max, 1.0f, 1.0f);
    }
}

๐Ÿ”” ํฌ์ŠคํŒ… ๊ณต์ง€
ใ…ใ…‡ใ„ดใ„ปใ„ดใ…‡

ํƒœ๊ทธ:

์นดํ…Œ๊ณ ๋ฆฌ:

์—…๋ฐ์ดํŠธ: