Notice
Recent Posts
Recent Comments
Link
«   2024/07   »
1 2 3 4 5 6
7 8 9 10 11 12 13
14 15 16 17 18 19 20
21 22 23 24 25 26 27
28 29 30 31
Archives
Today
Total
관리 메뉴

브래의 슬기로운 코딩 생활

모바일 게임 개발 11주차 정리 본문

2-1/모바일 게임 개발

모바일 게임 개발 11주차 정리

김브래 2023. 5. 18. 15:41

CharacterController컴포넌트

주로 FPSTPS 게임의 플레이를 구현할 때 사용
RigidbodyCapsule Collider 기능을 포함하고 있음

CharacterController controller ; //CharacterController 변수 정의

controller = GetComponent<CharacterController> () ;

//스크립트가 부착된 object의 구성요소에 CharacterController controller 변수에 대입

 

currentMovement += Vector3.forward * Time.deltaTime * 1.0f ;

// 1초에 1m 앞으로 가는 속도를 currentMovement에 추가한다.

 

controller.Move (currentMovement * Time.deltaTime);

controller.Move (벡터) // 벡터만큼 controller 이동

controller.isGrounded->true, false // controller가 바닥에 닿았는가를 체크

 

void Start()

    {      reset_pos = transform.position;    }

void Update()

    {     

       if (~~)

        {

            transform.position = reset_pos;//처음 위치로 이동

            currentMovement = new Vector3(0, 0, 0); // 속력 0으로 초기화

        }

    }

 

void Update () {

    if (~~~) {

    direction *= -1 ; //만약 ~~~ 하 direction -1 곱하여 역방향으로 전환

    }

transform.Translate (Vector3.right  * direction  * Time.deltaTime); // 같은 속도로 역방향으로 전환됨

}

 

카메라가 객체를 따라다니는 소스

transform.Translate (camera_move, Space.World);

// 오브젝트가 움직일 때 기준이 되는 축이 해당 물체가 아니라 World (기즈모기준)

 

transform.Translate (camera_move, Space.Self);

// 오브젝트가 움직일 때 기준이 되는 축이 해당 물체일 경우 Self(지정하지 않을 경우 Self)

 

public Transform target;// 객체

Vector3 camera_move;

void Update()

{  

    camera_move = new Vector3(타켓의 X축위치, Y0 위치, 타켓의 Z축위치); // 카메라의 위치

    transform.Translate(camera_move, Space.World);//카메라의 위치 이동

    transform.LookAt(target);//카메라가 target을 바라 봄

}

 

camera_move = new Vector3(target.position.x - transform.position.x, 0, target.position.z - (transform.position.z + 10));

카메라 위치 = [객체가 움직인 x위치-현재 카메라의 x위치, 0 , 객체가 움직인 z축 위치 – (현재 카메라의 z축 위치 +10)]