μΌ | μ | ν | μ | λͺ© | κΈ | ν |
---|---|---|---|---|---|---|
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 |
- νν μ€
- νμ΄μ¬
- BFS
- μ€λΈμ
- kraftonjungle
- μκ³ λ¦¬μ¦
- λ€μ΅μ€νΈλΌ
- λ°±μ€
- TiL
- project3
- ν¬λνν€ μ κΈ 4κΈ°
- anonymous page
- C
- 4κΈ°
- ν°μ€ν 리μ±λ¦°μ§
- ν¬λνν€ μ κΈ
- User Stack
- μ λν°
- ν¬λνν€μ κΈ4κΈ°
- μ΄λ²€νΈ ν¨μ μ€ν μμ
- μΆμν΄λμ€μμΈν°νμ΄μ€
- pintos
- Unity
- ν¬λνν€μ κΈ
- KRAFTON JUNGLE
- μ μ-μ ν¬
- μ°κ²°λ¦¬μ€νΈ
- μκ³ λ¦¬μ¦μμ -λλΉμ°μ νμ2
- c#
- λ€νΈμν¬
- Today
- Total
λ§κ°λ‘κ·Έ
ν¬λνν€ μ κΈ WEEK12 DAY 91 - μ€ν κ³΅λΆ : μ λν° 3D νλ μ΄μ΄ μμ§μ & μ‘°μ΄μ€ν± μ‘°μ λ³Έλ¬Έ
ν¬λνν€ μ κΈ WEEK12 DAY 91 - μ€ν κ³΅λΆ : μ λν° 3D νλ μ΄μ΄ μμ§μ & μ‘°μ΄μ€ν± μ‘°μ
habbn 2024. 4. 6. 21:32π2024.04.06
1. μ λν° 3d νλ μ΄μ΄ μμ§μ & μ‘°μ΄μ€ν± μ‘°μ
2. λ°±μ€ μ μ-μ ν¬
μ€λμ μ‘°μ΄μ€ν±μΌλ‘ νλ μ΄μ΄ μμ§μ μ‘°μμ ꡬννμλ€.
μ‘°μ΄μ€ν±μ μ¬μ©ν΄μ μμ§μμ ꡬννλ 건 μ²μμ΄λΌ νλνλ λ°°μκ°λ©΄μ νλ€!
μ‘°μ΄μ€ν± μ‘°μμ νκΈ° μν΄μ μ‘°μ΄μ€ν± μμ μ λ€μ΄λ°μμΌ νλ€.
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;
void Awake()
{
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"));
}
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);
}
//μ
λ ₯ λ°©ν₯μ λ°λ₯Έ λͺ©ν μλ
//inputDir.magnitudeλ μ
λ ₯ 벑ν°μ ν¬κΈ°λ‘ μ¬μ©μκ° μ
λ ₯ν λ°©ν₯μ ν¬κΈ°μ ν΄λΉ
targetSpeed = moveSpeed * inputDir.magnitude;
//νμ¬ μλλ₯Ό λͺ©ν μλλ‘ λΆλλ½κ² μ‘°μ νλ€.
//SmoothDamp νμ¬ μλλ₯Ό λͺ©ν μλλ‘ μΌμ ν μκ°(smoothMoveTime)λμ λΆλλ½κ² λ³ν
//speedVelocityλ μλμ λ³νλμ μΆμ νλλ° μ¬μ©λλ λ³μμ΄λ©°,
//ref ν€μλλ₯Ό ν΅ν΄ μ΄ κ°μ ν¨μ λ΄μμ μ§μ λ³κ²½ν μ μλ€.
currentSpeed = Mathf.SmoothDamp(currentSpeed, targetSpeed, ref speedVelocity, smoothMoveTime);
//νμ¬ μ€νΌλμμ νκ² μ€νΌλκΉμ§ smoothMoveTime λμ λ³νλ€.
transform.Translate(transform.forward * currentSpeed * Time.deltaTime, Space.World);
}
}
μ‘°μ΄μ€ν±μ μ΄μ©ν΄μ μ΄λμ νκ²λ ꡬνμ νμκ³ ν μ€νΈλ₯Ό μν΄μ enableMobile boolν λ³μλ₯Ό λ§λ€μ΄μ ν€λ³΄λ μ λ ₯μΌλ‘λ μ΄λν μ μκ²λ νμλ€. (ν°μΉν¨λμ μ΄λμ΄ λμμ λλμ§ νμΈνκΈ° μν΄ λλ²κΉ μ©μΌλ‘ λ§λ κ²μ΄λ€.)
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);
}
μ΄ λΆλΆμ μ λ ₯μ΄ μλ κ²½μ° μ λ ₯ λ°©ν₯μΌλ‘ μΊλ¦ν°λ₯Ό νμ μν€λ μν μ νκΈ° μν΄ κ°λλ₯Ό ꡬν΄μ£Όλ μ½λμ΄λ€.
1 . Mathf.Atan2(inputDir.x, inputDir.y)λ μ λ ₯ 벑ν°μ xμ μ λ ₯ 벑ν°μ y λ₯Ό μ¬μ©νμ¬ κ°λλ₯Ό κ³μ°νλ€.
2. Mathf.Rad2Deg λ₯Ό μ¬μ©ν΄μ λΌλμ κ°μ κ°λλ‘ λ³ννλ€.
-> Mathf.Atan2λ λΌλμμ returnνκΈ°μ λ€μ κ°λλ‘ λ°κΏμ£Όλ Mathf.Rad2Degλ₯Ό κ³±ν΄μ€λ€.
3. cameraTransform.eulerAngles.y λ μΉ΄λ©λΌμ νμ¬ yμΆ νμ κ°μ κ°μ Έμ¨λ€.
4. μ΄λ κ² κ³μ°λ νμ κ°μ μ¬μ©νμ¬ Mathf.SmoothDampAngle ν¨μλ‘ μΊλ¦ν°λ₯Ό λΆλλ½κ² νμ μν¨λ€.
-> Mathf.SmoothDampAngle ν¨μλ₯Ό μ¬μ©νλ©΄ νλ μ΄μ΄κ° λ±λ±νκ² μμ§μ΄μ§ μκ³ λΆλλ½κ² μμ§μ΄κ² λλ€.
-> Vector3.upμ yμΆμ μλ―Ένλ€.
λ°±μ€ : μ μ - μ ν¬
νμ΄ - bfs
import sys
from collections import deque
input = sys.stdin.readline
N, M = map(int,input().split())
peoples = [list(input().rstrip()) for _ in range(M)]
dx = [-1,1,0,0]
dy = [0,0,-1,1]
def bfs(a,b,color):
q = deque()
q.append((a,b))
cnt = 1
peoples[a][b]= "."
while q:
x, y = q.popleft()
for i in range(4):
nx = x + dx[i]
ny = y + dy[i]
if(0 <= nx < M and 0 <= ny < N and peoples[nx][ny] == color):
peoples[nx][ny] = "."
q.append((nx,ny))
cnt += 1
return cnt
w_result = 0
b_result = 0
for i in range(M):
for j in range(N):
if peoples[i][j] == "W":
w_result += bfs(i,j,"W") **2
elif peoples[i][j] == "B":
b_result += bfs(i,j,"B") **2
print(w_result, b_result)