Unity Character Controller ์ฌ์ฉํ๊ธฐ
๐ก navmesh ๋ง์ ์ฌ์ฉํ๋ค chacter controller์ ํผ์ฉ ์ฌ์ฉํ๋ ค๊ณ ์์๋ณด์๋ค.
Character Controller ๋
์ ๋ํฐ์์ ์ง์ํ๋ ์ปดํฌ๋ํธ๋ก ์ฃผ๋ก ์ฌ๋ ํํ์ ์บ๋ฆญํฐ ์์ง์๊ณผ ๊ด๋ จ๋ ์ ์ด๋ฅผ ์ํด ์ฌ์ฉํจ
- capsule ํํ์ collider๊ฐ ํฌํจ์ด ๋์ด์์ด ๋ณ๋์ collider๊ฐ ํ์์์
- ์ฌ๋ผ๊ฐ ์ ์๋ ๊ฒฝ์ฌ ๋์ด, ๊ณ๋จ, ๋ฑ์ ๋ํ ์ค์ ๋ ๊ฐ๋ฅ
- collider ๋ฒ์ ์ค์ ๊ฐ๋ฅ
์บ๋ฆญํฐ ์์ง์ด๋ ๋ฐฉ๋ฒ
- ChacterController ์ปดํฌ๋ํธ๋ฅผ ๊ฐ์ ธ์จ๋ค.
- move ํจ์๋ก ์์ง์ธ๋ค. ex) Move(direction * speed * Time.deltaTime);
- 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 ์ฒด๋ ฅ์ ๋ฐ๋ผ ์ด๋ฏธ์ง ์ฌ์ด์ฆ ์กฐ์
- ์ ๋์์์์ ์ ์ํ hpbar๋ฅผ ๊ธฐ์ค์ผ๋ก ์์ ํ๋ค
- hpbar์ ์ด๋ฏธ์ง์ scale์ ์ฒด๋ ฅ์ ๋น์จ์(current/max) ๋ฐ๋ผ ์กฐ์
- ์ด๋ฏธ์ง์ ํผ๋ฒ๋ฑ์ ์ ํ ์ ์ฌ๊ธฐ๋ฅผ ์ฐธ์กฐ ํ๋ค.
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);
}
}
๐ ํฌ์คํ
๊ณต์ง
ใ
ใ
ใดใปใดใ