일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
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 |
- 유니티 미연시
- unity 게임 개발
- 크래프톤 게임 정글 랩
- protobuf 란?
- 유니티
- 게임 개발 독학
- Unity 독학
- 크래프톤 정글 게임랩
- 크래프톤 정글랩
- 유니티 독학
- node.js
- 게임 독학
- 크래프톤 정글 게임 랩
- unity 개발
- protobuf란
- 유니티 스토리
- unity 공부
- 오픽 im1
- 게임 개발
- unity 게임
- ETRI 연구연수
- 유니티 퀘스트
- 크래프톤
- Unity Chess
- unity 강의
- 유니티 대화
- 오픽 im1 5일
- 유니티 체스
- unity 설치
- unity
- Today
- Total
하참이의 아이디어노트
Unity 강의 7일차 (1) - 시점 설정 본문
본 강의는 다음 문서를 참고하여 제작하였습니다. 자세한 내용은 하단 링크를 참조하시거나 댓글로 질문 남겨주시면 성심성의껏 답변 드리겠습니다.
4.1강 - 시점 설정 - Unity Learn
개요: 먼저 새 프로토타입을 만들고 시작 파일을 다운로드합니다. 아름다운 섬과 하늘, 파티클 효과 등 다양한 에셋이 있으며, 모두 커스터마이즈할 수 있습니다. 이제 플레이어가 섬을 중심으
learn.unity.com
하단 링크 또는 상단 문서에서 압축파일을 다운 받은 뒤, 새 프로젝트에서 Import 합니다.
하이어라키에서 구체를 생성하고 이름을 Player로 설정합니다. Scale을 x, y, z 전부 1.5로 설정합니다.
Player에게 Rigidbody 컴포넌트를 부여합니다.
Textures에 있는 아무 텍스쳐를 Player에게 드래그 합니다. 검은색이 눈에 띌 것 같습니다.
카메라 초점을 변경해보겠습니다. 빈 게임 오브젝트를 생성하고 이름을 Focal Point로 변경합니다.
그리고 카메라를 Focal Point의 자식 오브젝트로 드래그합니다.
새 스크립트 RotateCamera를 생성하고 스크립트 컴포넌트를 Focal Point에 부여합니다.
RotateCamera를 다음과 같이 작성합니다.
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class RotateCamera : MonoBehaviour
{
public float rotationSpeed;
// Start is called before the first frame update
void Start()
{
}
// Update is called once per frame
void Update()
{
float horizontalInput = Input.GetAxis("Horizontal");
transform.Rotate(Vector3.up, horizontalInput * rotationSpeed * Time.deltaTime);
}
}
Input.GetAxis("Horizontal")을 이용하여 좌우 회전을 입력받습니다.
transform.Rotate를 이용하여 Focal Point를 회전시킵니다. 이 경우는 이전에 배웠던 것을 카메라의 관점 포인트에 적용한 응용이라 볼 수 있죠. 이를 이용해 카메라가 맵 주위를 회전하는 연출을 할 수 있습니다.
Unity Editor에서 RotateCamera 컴포넌트의 Rotation Speed 값을 변경해 속도를 조절합시다. 저는 50으로 하겠습니다.
이제 플레이어가 앞으로 움직일 수 있도록 해보겠습니다.
PlayerController 스크립트를 생성하고 Player 에게 부착한뒤, 다음과 같이 작성합니다.
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class PlayerController : MonoBehaviour
{
private Rigidbody playerRb;
public float speed = 5.0f;
// Start is called before the first frame update
void Start()
{
playerRb = GetComponent<Rigidbody>();
}
// Update is called once per frame
void Update()
{
float forwardInput = Input.GetAxis("Vertical");
playerRb.AddForce(Vector3.forward * speed * forwardInput);
}
}
AddForce를 이용하여 구체가 자연스럽게 굴러가도록 제작하였습니다. 설명은 생략하겠습니다.
하지만 전방과 후방만으로 움직이는 것은 저희가 원하는 방향이 아닙니다. 플레이어가 보는 방향, 즉 Focal Point 방향으로 움직이도록 수정하고 싶습니다. 다음과 같이 PlayerController를 수정합니다.
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class PlayerController : MonoBehaviour
{
private Rigidbody playerRb;
public float speed = 5.0f;
private GameObject focalPoint;
// Start is called before the first frame update
void Start()
{
playerRb = GetComponent<Rigidbody>();
focalPoint = GameObject.Find("Focal Point");
}
// Update is called once per frame
void Update()
{
float forwardInput = Input.GetAxis("Vertical");
playerRb.AddForce(focalPoint.transform.forward * speed * forwardInput);
}
}
Focal Point 게임오브젝트를 찾아서 해당 게임 오브젝트의 위치 앞으로 움직이도록 합니다.
'Unity > Unity 기초' 카테고리의 다른 글
Unity 강의 7일차 (3) - 파워업 및 카운트다운 (0) | 2025.01.22 |
---|---|
Unity 강의 7일차 (2) - 플레이어 따라가기 (0) | 2025.01.22 |
Unity 강의 6일차 (2) - 플레이어 제어 (0) | 2025.01.21 |
Unity 강의 6일차 (1) - 풍선, 폭탄, 부울 (0) | 2025.01.21 |
Unity 강의 5일차 (4) - 파티클 및 음향 효과 (0) | 2025.01.20 |