๋ณธ๋ฌธ์œผ๋กœ ๋ฐ”๋กœ๊ฐ€๊ธฐ
728x90

 

๋ชจ๋ฐ”์ผ ๊ฒŒ์ž„์—์„œ ์บ๋ฆญํ„ฐ ์ด๋™ ๋ฐฉ์‹์—๋Š” ์—ฌ๋Ÿฌ ๊ฐ€์ง€๊ฐ€ ์žˆ๋‹ค. ์กฐ์ด์Šคํ‹ฑ(Joystick)์„ ์‚ฌ์šฉํ•˜๊ธฐ๋„ ํ•˜์ง€๋งŒ, ์กฐ์ž‘๊ฐ์ด ๋ถˆํŽธํ•ด์„œ ํ™”๋ฉด ํ„ฐ์น˜๋ฅผ ๋งŽ์ด ์‚ฌ์šฉํ•˜๊ณ  ์žˆ๋Š” ์ถ”์„ธ๋ผ๊ณ  ํ•œ๋‹ค. PC ๊ฒŒ์ž„์—์„œ๋„ LOL์ด๋‚˜ ์Šคํƒ€ํฌ๋ž˜ํ”„ํŠธ ๊ฐ™์€ ๊ฒฝ์šฐ, ๋งˆ์šฐ์Šค๋ฅผ ํ†ตํ•ด ํ™”๋ฉด์˜ ์›ํ•˜๋Š” ์ง€์ ์œผ๋กœ ์บ๋ฆญํ„ฐ๋ฅผ ์ด๋™ ์‹œํ‚ค๋Š” ๋ฐฉ์‹์„ ์“ด๋‹ค.

 

์›๋ฆฌ

 

  • ์นด๋ฉ”๋ผ๊ฐ€ ๋ณด์—ฌ์ฃผ๋Š” ์˜์—ญ์— ํ„ฐ์น˜๋ฅผ ํ•˜๋ฉด, Raycast์ฒ˜๋Ÿผ ๊ฐ€์ƒ์˜ ๊ด‘์„ ์„ ์œ๋‹ค.
  • ๊ด‘์„ ์— ๋‹ฟ์€ ๋ฐ”๋‹ฅ์˜ ์ขŒํ‘œ๊ฐ’์„ ๋ฐ›์•„๋‚ด์„œ, ์บ๋ฆญํ„ฐ๋ฅผ ํ•ด๋‹น ์ขŒํ‘œ๋กœ ์ด๋™ ์‹œํ‚จ๋‹ค.
  • ์ฆ‰, ์Šคํฌ๋ฆฐ ์ขŒํ‘œ๊ณ„์—์„œ ์›”๋“œ ์ขŒํ‘œ๊ณ„๋กœ์˜ ๊ฐ’ ๋ณ€ํ™˜ ๊ณผ์ •์ด ํ•„์š”ํ•˜๋‹ค.
  • ๋ฐ”๋‹ฅ์— ์ฝœ๋ผ์ด๋”(Collider) ์ปดํฌ๋„ŒํŠธ๊ฐ€ ์žˆ์–ด์•ผ ๊ด‘์„ ์— ๋ถ€๋”ชํžˆ๋ฏ€๋กœ ๋ฐ˜๋“œ์‹œ ๋„ฃ์–ด์ค˜์•ผ ํ•œ๋‹ค.
  • ์žฅ์• ๋ฌผ์ด ์กด์žฌํ•œ๋‹ค๋ฉด, ๊ธธ์ฐพ๊ธฐ ์•Œ๊ณ ๋ฆฌ์ฆ˜์„ ์ถ”๊ฐ€๋กœ ์ ์šฉํ•ด์ค˜์•ผ ํ•œ๋‹ค. ์•„๋‹ˆ๋ฉด ๋„ค๋น„๊ฒŒ์ด์…˜์„ ์‚ฌ์šฉํ•˜๋Š” ๋ฐฉ๋ฒ•์ด ์žˆ๋‹ค.
  • ์”ฌ ๋‚ด์— ์žˆ๋Š” ์•„์ดํ…œ ํด๋ฆญ ์‹œ ์ด๋ฒคํŠธ๊ฐ€ ๋ฐœ์ƒํ•˜๊ฒŒ ํ•˜๋Š” ๋“ฑ์—๋„ ์‘์šฉํ•ด์„œ ์ ์šฉํ•  ์ˆ˜ ์žˆ๋‹ค.

 

๋ณด๊ณ  ์žˆ๋Š” ๋ฐฉํ–ฅ์„ ๋‚˜ํƒ€๋‚ด๊ธฐ ์œ„ํ•ด, ๊ตฌ์ฒด๋ฅผ ๋‹ฌ์•„์คฌ๋‹ค.

 

์Šคํฌ๋ฆฝํŠธ(Script)

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class Player : MonoBehaviour
{
    public float moveSpeed;
    private bool isMove;
    private Vector3 destination;

    void Update()
    {
        if (Input.GetMouseButtonDown(0))
        {
            RaycastHit hit;
            
            if(Physics.Raycast(Camera.main.ScreenPointToRay(Input.mousePosition), out hit))
            {
                Debug.Log($"์ถฉ๋Œ๋œ ๋ฌผ์ฒด ์ด๋ฆ„ : {hit.transform.name}, Position : {hit.point}");
                destination = hit.point;
                isMove = true;
            }
        }
        Move();
    }


    private void Move()
    {
        if (isMove)
        {
            bool isAlived = Vector3.Distance(destination, transform.position) <= 0.1f;
            if (isAlived)
            {
                isMove = false;
            }
            else
            {
                Vector3 direction = destination - transform.position;
                transform.forward = direction;
                transform.position += direction.normalized * moveSpeed * Time.deltaTime;
            }
        }
    }

}

 

 

 

 

728x90
๋ฐ˜์‘ํ˜•