์ผ | ์ | ํ | ์ | ๋ชฉ | ๊ธ | ํ |
---|---|---|---|---|---|---|
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 |
- ํฌ๋ํํค์ ๊ธ4๊ธฐ
- ํฌ๋ํํค์ ๊ธ
- pintos
- ์๊ณ ๋ฆฌ์ฆ์์ -๋๋น์ฐ์ ํ์2
- project3
- c#
- User Stack
- ํฌ๋ํํค ์ ๊ธ 4๊ธฐ
- ํ์ด์ฌ
- 4๊ธฐ
- C
- ์ฐ๊ฒฐ๋ฆฌ์คํธ
- ์ถ์ํด๋์ค์์ธํฐํ์ด์ค
- ๋ฐฑ์ค
- KRAFTON JUNGLE
- anonymous page
- ์ด๋ฒคํธ ํจ์ ์คํ ์์
- ํฌ๋ํํค ์ ๊ธ
- BFS
- ์ ์-์ ํฌ
- ์ ๋ํฐ
- ์ค๋ธ์
- TiL
- ๋คํธ์ํฌ
- ๋ค์ต์คํธ๋ผ
- Unity
- ์๊ณ ๋ฆฌ์ฆ
- ํํ ์ค
- ํฐ์คํ ๋ฆฌ์ฑ๋ฆฐ์ง
- kraftonjungle
- Today
- Total
๋ง๊ฐ๋ก๊ทธ
ํฌ๋ํํค ์ ๊ธ WEEK12 DAY 93 - ์ ๋ํฐ ํฐ์น ํจ๋๋ก ์นด๋ฉ๋ผ ์กฐ์ & ์ ๋๋ฉ์ด์ ์ ์ฉ ๋ณธ๋ฌธ
ํฌ๋ํํค ์ ๊ธ WEEK12 DAY 93 - ์ ๋ํฐ ํฐ์น ํจ๋๋ก ์นด๋ฉ๋ผ ์กฐ์ & ์ ๋๋ฉ์ด์ ์ ์ฉ
habbn 2024. 4. 8. 22:46๐2024.04.08
1. ์ ๋ํฐ ํฐ์น ํจ๋๋ก ์นด๋ฉ๋ผ ์กฐ์ & ์ ๋๋ฉ์ด์ ์ ์ฉ
2. UnityYAMLMerge ์ค์น
3. ๋ฐฑ์ค
์ด์ ์นด๋ฉ๋ผ ํ์ ์ด ํ๋ ์ด์ด ์ค์ฌ์ผ๋ก ์๋๊ณ ์ํ ์นด๋ฉ๋ผ ๋ง๋ฅ ์กฐ์๋์ด์ ์ค๋ ๋ค์ ์ ๋๋ก ์์ ํ์๋ค.
์ด ๋ถ ์ ํ๋ธ๋ฅผ ๋ณด๋ฉด์ ์ฐธ๊ณ ํ์๋ค.
https://www.youtube.com/watch?v=4611qmBWTC0
MainCamera.cs
using UnityEngine;
public class MainCamera : MonoBehaviour
{
public Transform target;
public float followspeed = 15f; //๋ฐ๋ผ๊ฐ๋ ์๋
public float sensitive = 7f; //๊ฐ๋
public float clampAngle = 50f; //์นด๋ฉ๋ผ ํ์ ๊ฐ๋์ ์ ํ
private float rotX;
private float rotY;
public Transform realCamera;
public Vector3 dirNormalized; //๋ฐฉํฅ๋ฒกํฐ
public Vector3 finalDir; //์ต์ข
๋ฐฉํฅ
public float minDistance; //์ต์ ๊ฑฐ๋ฆฌ
public float maxDistance; //์ต๋ ๊ฑฐ๋ฆฌ
public float finalDistance; //์ต์ข
๊ฑฐ๋ฆฌ
public float smoothness = 10f;
public FixedTouchField touchField;
public bool enableMobile = false;
void Start()
{
rotX = transform.localRotation.eulerAngles.x;
rotY = transform.localRotation.eulerAngles.y;
dirNormalized = realCamera.localPosition.normalized;
//magnitude๋ ๋ฒกํฐ์ ๊ธธ์ด(ํฌ๊ธฐ)๋ฅผ ๋ฐํํ๋ ๋ฉ์๋
finalDistance = realCamera.localPosition.magnitude;
}
void Update()
{
if (enableMobile)
{
rotY += touchField.TouchDist.x * sensitive * Time.deltaTime;
rotX -= touchField.TouchDist.y * sensitive * Time.deltaTime;
}
else
{
rotY += Input.GetAxis("Mouse X") * sensitive * Time.deltaTime;
rotX -= Input.GetAxis("Mouse Y") * sensitive * Time.deltaTime;
}
rotX = Mathf.Clamp(rotX, -clampAngle, clampAngle); //๊ฐ๋์ ๋ฒ์
Quaternion rot = Quaternion.Euler(rotX, rotY, 0); //์นด๋ฉ๋ผ์ ํ์
transform.rotation = rot;
}
void LateUpdate()
{
transform.position = Vector3.Lerp(transform.position, target.position, followspeed * Time.deltaTime);
//transform.TransformPoint() ๋ก์ปฌ ์ขํ๊ณ์์ ์ง์ ๋ ์ง์ ์ ์๋ ์ขํ๊ณ๋ก ๋ณํ
finalDir = transform.TransformPoint(dirNormalized * maxDistance);
RaycastHit hit;
//์นด๋ฉ๋ผ์ ํ์ฌ ์์น์ ์ต์ข
์์น ์ฌ์ด์ ์ฅ์ ๋ฌผ์ด ์๋์ง ๊ฒ์ฌ
//์ฅ์ ๋ฌผ์ด ์์ผ๋ฉด hit ๋ณ์์ ์ ๋ณด๊ฐ ์ ์ฅ
if(Physics.Linecast(transform.position, finalDir, out hit))
{
//minDistance์ maxDistance ์ฌ์ด์ ๊ฐ์ ์ ์งํ๋๋ก ๊ฑฐ๋ฆฌ๋ฅผ Clampํจ
finalDistance = Mathf.Clamp(hit.distance, minDistance, maxDistance);
}
else
{
finalDistance = maxDistance;
}
//Lerp ํจ์๋ฅผ ์ฌ์ฉํ์ฌ ์ค์ ์นด๋ฉ๋ผ์ ๋ก์ปฌ ์์น๋ฅผ ๋ฐฉํฅ ๋ฒกํฐ์ ์ต์ข
๊ฑฐ๋ฆฌ์ ๋ง๊ฒ ๋ถ๋๋ฝ๊ฒ ์ด๋
realCamera.localPosition = Vector3.Lerp(realCamera.localPosition, dirNormalized * finalDistance, Time.deltaTime * smoothness);
}
}
Mathf.Clamp ํจ์๋ ์ฃผ์ด์ง ๊ฐ์ ๋ฒ์๋ฅผ ์ง์ ๋ ์ต์๊ฐ๊ณผ ์ต๋๊ฐ ์ฌ์ด๋ก ์ ํํ๋๋ฐ ์ฌ์ฉ๋๋ค.
TransformPoint() ํจ์๋ ๋ก์ปฌ ์ขํ๊ณ์์ ์ง์ ๋ ์ง์ ์ ์๋ ์ขํ๊ณ๋ก ๋ณํํ๋๋ฐ ์ฌ์ฉ๋๋ค.
public Vector3 TransformPoint(Vector3 position);
โข position์ ํ์ฌ ๊ฐ์ฒด์ ๋ก์ปฌ ์ขํ๊ณ์์์ ์์น
โข TransformPoint๋ ํด๋น ์ง์ ์ ์๋ ์ขํ๊ณ๋ก ๋ณํํ์ฌ ๋ฐํํ๋ค.
์ด ๋ฉ์๋๋ ์ฃผ๋ก ๊ฐ์ฒด์ ๋ก์ปฌ ์ขํ๊ณ์์ ํน์ ์ง์ ์ ์๋ ์ขํ๊ณ๋ก ๋ณํํ ๋ ์ฌ์ฉ๋๋ค. ์ฃผ๋ก ํน์ ์ง์ ์ ์ ๋ ์์น๋ฅผ ์ป๊ฑฐ๋, ํด๋น ์ง์ ์ ๋ค๋ฅธ ๊ฐ์ฒด์ ๊ณต๊ฐ์์ ์ฌ์ฉํ ๋ ์ ์ฉํ๋ค.
๊ทธ๋ฆฌ๊ณ ๋ฐ๋ฐํ ํ๋ ์ด์ด ์ด๋์ ์ ๋๋ฉ์ด์ ์ ์ ํ์ฃผ์๋ค.
PlayerController.cs
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class PlayerController : MonoBehaviour
{
public bool enableMobile = false;
[SerializeField]
private float smoothRotationTime; //target ๊ฐ๋๋ก ํ์ ํ๋๋ฐ ๊ฑธ๋ฆฌ๋ ์๊ฐ
[SerializeField]
private float smoothMoveTime; //target ์๋๋ก ๋ฐ๋๋๋ฐ ๊ฑธ๋ฆฌ๋ ์๊ฐ
[SerializeField]
private float moveSpeed;
private float rotationVelocity;
private float speedVelocity;
private float currentSpeed;
private float targetSpeed;
Transform cameraTransform;
public VariableJoystick joystick;
Animator anim;
void Awake()
{
anim = GetComponent<Animator>();
cameraTransform = Camera.main.transform;
}
void Update()
{
Vector2 input = Vector2.zero;
if (enableMobile)
{
input = new Vector2(joystick.input.x, joystick.input.y);
}
else
{
input = new Vector2(Input.GetAxisRaw("Horizontal"), Input.GetAxisRaw("Vertical"));
}
anim.SetBool("IsWalk", input != Vector2.zero);
Vector2 inputDir = input.normalized;
//์์ง์์ ๋ฉ์ท์ ๋ ๋ค์ ์ฒ์ ๊ฐ๋๋ก ๋์๊ฐ๋ ๊ฑธ ๋ง๊ธฐ ์ํจ
if (inputDir != Vector2.zero)
{
float rotation = Mathf.Atan2(inputDir.x, inputDir.y) * Mathf.Rad2Deg + cameraTransform.eulerAngles.y;
transform.eulerAngles = Vector3.up * Mathf.SmoothDampAngle(transform.eulerAngles.y, rotation, ref rotationVelocity, smoothRotationTime);
}
//์
๋ ฅ ๋ฐฉํฅ์ ๋ฐ๋ฅธ ๋ชฉํ ์๋
targetSpeed = moveSpeed * inputDir.magnitude;
//ํ์ฌ ์๋๋ฅผ ๋ชฉํ ์๋๋ก ๋ถ๋๋ฝ๊ฒ ์กฐ์
currentSpeed = Mathf.SmoothDamp(currentSpeed, targetSpeed, ref speedVelocity, smoothMoveTime);
//ํ์ฌ ์คํผ๋์์ ํ๊ฒ ์คํผ๋๊น์ง smoothMoveTime ๋์ ๋ณํ๋ค.
transform.Translate(transform.forward * currentSpeed * Time.deltaTime, Space.World);
}
void OnTriggerStay(Collider other) {
if (other.gameObject.tag == "NoticeBoard") {
Debug.Log("NoticeBoard");
}
}
}

ํ์ฌ๊น์ง ํ๋ ์ด์ด ์ด๋ & ์นด๋ฉ๋ผ ํ์ ์ ์๋ฃ๋ ์ํ์ด๋ค~
์ถ๊ฐ๋ก ๋ก๊ทธ์ธ & ํ์๊ฐ์ & ์บ๋ฆญํฐ ์ ํ ์ฐฝ์ ๊ฐ์ ํ์์ด ์บ๋ฆฌํด๋ฒ๋ ค์
๋ด์ผ๋ถํฐ ๊ฒ์ํ ์์ฑ ๋ถ๋ถ ๊ตฌํ ๊ณํ์ด๋ค.
๋ฐฑ์ค
์์ ๊ฒฝ๋ก ๋ฌธ์ ๋ฅผ ํ๋ ค๊ณ ํ๋๋ ์๋ผํ ์คํ ๋ค์ค์ ์ฒด๋ฅผ ์์์ผ ํ๋ค๊ณ ํด์ ์๋ผํ ์คํ ๋ค์ค์ ์ฒด ๊ณต๋ถ๋ฅผ ํ์๋ค.
์๋ผํ ์คํ ๋ค์ค์ ์ฒด๋ ๋ค์์ ์์ฐ์์ ๋ํ์ฌ ์์ ์ฌ๋ถ๋ฅผ ํ๋ณํ ๋ ์ฌ์ฉํ๋ ๋ํ์ ์ธ ์๊ณ ๋ฆฌ์ฆ์ด๋ค.
[๋ฐฑ์ค] 2960๋ฒ ์๋ผํ ์คํ ๋ค์ค์ ์ฒด (ํ์ด์ฌ)
์๋ผํ ์คํ ๋ค์ค์ ์ฒด ๋ค์์ ์์ฐ์์ ๋ํ์ฌ ์์ ์ฌ๋ถ๋ฅผ ํ๋ณํ ๋ ์ฌ์ฉํ๋ ๋ํ์ ์ธ ์๊ณ ๋ฆฌ์ฆ์ด๋ค. ์๋ผํ ์คํ ๋ค์ค์ ์ฒด๋ N๋ณด๋ค ์๊ฑฐ๋ ๊ฐ์ ๋ชจ๋ ์์๋ฅผ ์ฐพ์ ๋ ์ฌ์ฉํ ์ ์๋ค. ๋์ ๊ณผ
habbn-unitystudy.tistory.com