언리얼 에디터에서 컴파일을 했는데도 변경사항이 적용되지 않거나 뭔가 헛컴파일을 도는 느낌이라면

(비주얼스튜디오 에디터와 언리얼 에디터의 싱크가 맞지 않는 것 같다면)

 

다시 빌드를 눌러보거나

 

비주얼스튜디오 프로젝트 파일을 재생성해보자

 

svn, git 등의 원격... 클라우드? 버전 관리 툴 사용 시 종종 일어나는 일이라고 한다.

 

 

'[햄] 작업일기' 카테고리의 다른 글

230530  (0) 2023.05.31
230528  (0) 2023.05.28
230527  (0) 2023.05.27
230509  (0) 2023.05.09
230508  (0) 2023.05.08

남이 쓴 상호작용 기능 구현 코드이다.

void AHamsterDemoCharacter::SetupPlayerInputComponent(class UInputComponent* PlayerInputComponent)
{
	...
	PlayerInputComponent->BindAction("Interaction", IE_Pressed, this, &AHamsterDemoCharacter::OnInteract);
	...
}


void AHamsterDemoCharacter::OnInteract()
{

}


// 업데이트 문
void AHamsterDemoCharacter::Tick(float DeltaSeconds)
{
	Super::Tick(DeltaSeconds);

	FHitResult hitResult;
	if (TraceOn(hitResult))
	{
		auto interactableObj = TraceInteractableObject(hitResult); // 감지한 물체가 상호 작용 가능한 물체인 지 체크
		if (interactableObj != nullptr)
		{
			bool isSuccessInteract = interactableObj->Interact(); // 물체에게 상호 작용 시도
			if (isSuccessInteract)
			{
				// 상호 작용 성공 시 캐릭터가 할 행동 
			}
		}
	}
}


AInteractableObject* AHamsterDemoCharacter::TraceInteractableObject(struct FHitResult& inHit)
{
	auto actor = inHit.GetActor();
	if (actor == nullptr)
		return nullptr;

	return Cast<AInteractableObject>(actor);
}


bool AHamsterDemoCharacter::TraceOn(struct FHitResult& OutHit)
{
	auto startPos = GetSpawnFVector();
	auto forwardVector = GetGunRightFVector();
	float TraceOffset = 500.0f;

	FVector endPos = ((forwardVector * TraceOffset) + startPos);

	FCollisionQueryParams CollisionParams;

	return GetWorld()->LineTraceSingleByChannel(OutHit, startPos, endPos, ECollisionChannel::ECC_WorldStatic, CollisionParams);
}

상호 작용 가능한 물체/인물에 다가가면 E키를 누르라는 UI가 보이고,

E키를 눌러 상호작용 시 대화, 탑승 등의 추가 이벤트로 넘어가게 된다.

 

키보드에서 E키를 눌렀을 때 OnInteract() 가 발동됨

 

Tick 함수에서 매 틱마다 (프레임마다, 즉 1초에 60회정도) 판정하는 내용은 다음과 같다.

 

TraceOn(HitResult)에 값이 있는지?

TraceOn 에서는

LineTraceSingleByChannel (RayCast 기능) 을 사용해서, WorldStatic 인 콜리전만 찾음 (WorldStatic은 static mesh에만 적용되는 속성이므로, static mesh를 찾는다는 뜻)

TraceOn은 ray를 맞은 애인 OutHit을 리턴

 

TraceOn(HitResult)가 nullptr가 아니면 if 문 진입 (ray 맞은 애가 있다면)

TraceInteractableObj 에서 Ray를 맞은 애가 액터인지 & 상호작용 가능한지 (interactable인지) 확인하고 리턴

 

interactableObj가 nullptr가 아니면 if문 진입 (상호작용 가능하다면)

interactableObj에 Interact() (상호작용 시도)

 

 

if(isSucessInteract) 전까지는 모두 interact 여부 판단을 위한 코드임

그 이후로는 상호작용에 성공했을 시 취할 행동의 코드를 기술하면 된다.

 

OnInteract() 에서 (E키가 눌렸을 때)

조건에 맞지 않으면 무시하고

조건에 맞으면 진행한다.

 

+) InteractableObj 또는 isSuccessInteract 를 (혹은 둘 다를) 지역변수가 아닌 멤버 변수로 선언해서

OnInteract()에서 가져다가 판정할 수 있게 해도 좋을 것 같음.

 

'E 누르기' UI는 Interact()에서 띄우게 해도 된다

단, 이미 UI가 떠 있으면 띄우지 않게, 다른 사람이 이미 대화 중이라면 띄우지 않게, 퀘스트를 이미 클리어했다면 띄우지 않게 하기 등 예외처리가 필요하다.

 

Interact() 에서 E누르기가 가능해서 E를 누른 이후의 처리는 OnInteract() 에서 진행한다 (대화창 등)

 

 


 

11줄을 조정하면 구체의 크기가 바뀌고, 31줄을 조정하면 총알이 남아있는 시간이 바뀔 줄 알았는데...

의외로 그렇게 간단히 바뀌지는 않는 것 같다 (확실하지 않음)

 

bShouldBounce를 false로 하면 공이 맞은 곳에 그대로 붙어 버린다. 찍찍이공처럼!

 

AddImpulse를 통해 뭔가 뭔가 할 수 있을 것 같다.

 

총알이 닿았을 때 이펙트가 터지는 건 어떻게 해야 할 지 아직 잘 모르겠다...

https://docs.unrealengine.com/4.27/ko/Basics/Actors/DecalActor/

https://velog.io/@kjinwoo12/%EC%96%B8%EB%A6%AC%EC%96%BC-%EC%97%94%EC%A7%84-%EB%84%A4%ED%8A%B8%EC%9B%8C%ED%81%AC-FPS-%EA%B2%8C%EC%9E%84-%EA%B0%9C%EB%B0%9C-%EC%9D%BC%EC%A7%805-%EC%B4%9D%EC%95%8C-%EC%9E%90%EA%B5%ADBullet-holes-%EB%8D%B0%EC%B9%BCDecal

 

아이디어: 데칼 사용? remote procedure call 사용?

'[햄] 작업일기' 카테고리의 다른 글

230530  (0) 2023.05.31
230528  (0) 2023.05.28
230527  (0) 2023.05.27
230516  (0) 2023.05.16
230508  (0) 2023.05.08

 

아래 두 사진의 float Val 과 float Value는 동일하다

...우째서?

 

shift를 눌렀을 때 이동 속도가 두 배가 되는 Sprint 기능을 구현 중이다.

잘못된 키 바인딩 (;;)

옳게 된 키 바인딩.........

ㅠㅠ

'[햄] 작업일기' 카테고리의 다른 글

230530  (0) 2023.05.31
230528  (0) 2023.05.28
230527  (0) 2023.05.27
230516  (0) 2023.05.16
230509  (0) 2023.05.09

https://www.acmicpc.net/problem/1620

백준 1620번: 나는야 포켓몬 마스터 이다솜

맵을 써본 적이 없어서 벡터로 해결하려고 난리치다가 시간 제한에 걸리는 바람에 엄청 헤맸다.

#include <iostream>
#include <string>
#include <vector>
using namespace std;


int main()
{
	ios_base::sync_with_stdio(0);
	cin.tie(NULL);
	
	int pokemon, question;
	string temp;

	vector<pair<int, string>>dic;

	cin >> pokemon >> question;

	for (int i = 0; i < pokemon; i++)
	{
		cin >> temp;
		dic.push_back({ i + 1, temp });
	}

	for (int i = 0; i < question; i++)
	{
		cin >> temp;

		if (temp[0] >= 65 && temp[0] <= 90)
		{
			for (int j = 0; j < pokemon; j++)
			{
				if (dic[j].second == temp)
				{
					cout << dic[j].first << "\n";
					break;
				}
			}
		} // 이름 들어옴, 숫자 찾기
		else
		{
			cout << dic[stoi(temp) - 1].second << "\n";
		} //숫자 들어옴
	}
}

벡터로 해결해보려고 노력했던 코드. 의도한 출력이 나오긴 한다.

find를 사용했어도 find의 내부는 for문이기 때문에 시간 초과가 나오는 건 똑같았을 것이다.

 

결국 map을 사용하여 해결...

#include <iostream>
#include <string>
#include <map>
using namespace std;

int main()
{
	ios_base::sync_with_stdio(0);
	cin.tie(NULL);

	int pokemon, question;
	string temp;
	int numTemp;
	map<string, int> nameDic;
	map<int, string> numDic;

	cin >> pokemon >> question;

	for (int i = 0; i < pokemon; i++)
	{
		cin >> temp;
		nameDic.insert({ temp, i + 1 });
		numDic.insert({ i + 1, temp });
	}

	for (int i = 0; i < question; i++)
	{
		cin >> temp;

		if (temp[0] >= 65 && temp[0] <= 90)
		{
			cout << nameDic[temp] << "\n";
		} //이름 들어옴, 숫자 찾기
		else
		{
			numTemp = stoi(temp);
			cout << numDic[numTemp] << "\n";
		} //숫자 들어옴, 이름 찾기
	}
}

key로 value를 찾는 건 가능한데, for문을 사용하지 않고 value로 key를 찾는 방법은 없을까?

value로 key가 찾고 싶어서 또 한참 방황하다가 결국

<string, int> 맵 하나, <int, string> 맵 하나, 이렇게 두 개를 사용하는 것으로 해결했다.

 

도움을 받은 글

https://life-with-coding.tistory.com/305

 

[C++][STL] map 사용법 정리

인트로 안녕하세요. 오늘은 C++ STL 연관 컨테이너 중 하나인 map에 대해 알려드리겠습니다. 목차 1) Map이란? 2) Map 기본 형태 3) Map 정렬 4) Map 사용방법 - 헤더 포함 - map 선언 - search : map에서 데이터

life-with-coding.tistory.com

https://psh50zmfhtm.tistory.com/m/5

 

[C++] map과 unordered_map

기본적으로 map과 unordered_map은 key, value의 한 쌍으로, pair 형태를 띄는 자료구조입니다. map map은 아래와 같은 형태의 RB Tree로 이루어져 있습니다. (이해하는 데 도움을 받은 링크를 첨부합니다.) 요

psh50zmfhtm.tistory.com

 

https://www.acmicpc.net/problem/10814

백준 10814번: 나이순 정렬

#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;


bool compare(pair<int, string> a, pair<int, string> b)
{
	return a.first < b.first;
}

int main()
{
	int num;
	int age;
	string name;
	vector<pair<int, string>> members;

	cin >> num;

	for (int i = 0; i < num; i++)
	{
		cin >> age >> name;
		members.push_back({ age, name });
	}

	stable_sort(members.begin(), members.end(), compare);

	for (int i = 0; i < num; i++)
	{
		cout << members[i].first << ' ' << members[i].second << "\n";
	}
}

stable_sort 대신 그냥 sort를 쓰게 되면,

algorithm 헤더의 기본 sort는 quicksort를 사용하여, 정렬 과정에서 입력된 순서가 보장되지 않을 수 있음

정렬 관련 참고 > https://code-lab1.tistory.com/24

 

[알고리즘] 기본 정렬 알고리즘 비교| stable vs not stable| in-place vs not in-place | 선택 정렬(selection sort)

정렬 알고리즘이란? 정렬 알고리즘은 n개의 숫자가 주어졌을 때 이를 사용자가 지정한 기준에 맞게 정렬하는 알고리즘이다. 아주 간단한 알고리즘부터 조금 복잡한 알고리즘까지, 여러가지 알

code-lab1.tistory.com

 

 

https://www.acmicpc.net/problem/2108

백준 2108번: 통계학

#include <iostream>
#include <cmath>
#include <algorithm>
using namespace std;


int nums[500001];

int main()
{
	int N;
	
	int average = 0;
	int middle = 0;
	int range = 0;


	cin >> N;

	
	for (int i = 0; i < N; i++)
	{
		cin >> nums[i];
	}

	sort(nums, nums + N);


	//평균
	double sum = 0;

	for (int i = 0; i < N; i++)
	{
		sum += nums[i];
	}

	average = round(sum / N);

	
	//중앙값
	int midNum = N / 2;
	middle = nums[midNum];


	//최빈값  잘 모르겠음
	int most[2] = { -9999, -9999 };
	int max = 0;
	int count = 1;
	int resultMost;
	
	nums[N] = -9999;

	for (int i = 0; i < N; i++)
	{
		if (nums[i] == nums[i + 1])
		{
			count++;
		}
		else
		{
			if (count > max)
			{
				max = count;
				most[0] = nums[i];
				most[1] = -9999 ;
			}
			else if (count == max)
			{
				if (most[1] == -9999)
				{
					most[1] = nums[i];
				}
			}
			count = 1;
		}
	}

	if (most[1] != -9999)
	{
		resultMost = most[1];
	}
	else
	{
		resultMost = most[0];
	}

	
	range = nums[N - 1] - nums[0];


	//출력
	cout << average << "\n" << middle << "\n" 
		<< resultMost << "\n" << range;
}

최빈값을 구하는 과정에서 아주 많이 헤맸다.

평균을 구할 때 쓰는 sum 변수는 float 형이 아닌 double 형으로 선언했어야 했다.

https://www.acmicpc.net/problem/4948

백준 4948번: 베르트랑 공준

 

초기 코드 (시간 초과)

#include <iostream>
using namespace std;

int main()
{
	int n;

	while (true)
	{
		cin >> n;

		if (n == 0)
		{
			break;
		}

		int count = 0; //소수 개수 카운트
		int temp = n;

		while (temp != 2*n)
		{
			bool check = true;

			for (int i = 2; i < temp; i++)
			{
				if (temp % i == 0)
				{
					check = false; //소수가 아니면 check=0
				}
			}

			if (check == true)
			{
				count++;
			}
			temp++;
		}
		cout << count << endl;	
	}
}

 

최종 코드

#include <iostream>
#include <cmath>
using namespace std;


int main()
{
	int n;
	bool tempList[123456*2 + 1] = { 0, };

	while (true)
	{
		cin >> n;

		if (n == 0)
		{
			break;
		}

		int count = 0; //소수 개수 카운트
		int temp = n+1;
		
		while (temp <= 2*n)
		{
			bool check = true;

			if (tempList[temp] == 1)
			{
				count++;
				temp++;
				continue;
			}

			for (int i = 2; i <= sqrt(temp); i++)
			{
				if (temp % i == 0)
				{
					check = false; //소수가 아니면 check=0
					break; //이미 판정 끝나서 더 할 필요 없음
				}
			}

			if (check == true)
			{
				count++;
				tempList[temp] = 1;
			}
            
			temp++;
		}

		cout << count << endl;	
	}
}

에라토스테네스의 체의 원리를 활용해서 (아직 체를 정확히는 모름...)

: 제곱근까지만 for문을 돌아도 됨 (제곱근 위로는 어차피 제곱근 아래에 짝이 있어서 이미 소수가 아닌 것으로 판정)

그렇게 이미 구한 소수를 배열에 저장, 다음 번 판정에 활용하여 시간 단축

 

 

'백준' 카테고리의 다른 글

[백준] 10814번: 나이순 정렬  (0) 2023.01.14
[백준] 2108번: 통계학  (0) 2023.01.08
[백준] 1193번: 분수찾기 (C++)  (0) 2022.12.08
[백준] 1018번: 체스판 다시 칠하기 (C++)  (0) 2022.03.29
[백준] 7568번: 덩치 (C++)  (0) 2022.03.19

https://www.acmicpc.net/problem/1193

백준 1193번: 분수찾기

#include <iostream>
using namespace std;

int main()
{
	int X, Y = 0; //입력: X
	int a = 0; // X번째 수는 Y번째 줄의 a번째 수
	int b = 0; //Y를 찾기 위해 임시로 사용하는 값
	cin >> X;

	if (X == 1) { cout << "1/1"; }
	else if (X == 2) { cout << "1/2"; }
	else if (X == 3) { cout << "2/1"; }
	else
	{
		for (int i = 3; i; i++)
		{
			b = i * (i + 1) / 2;
			if (X <= b) { Y = i; break; }
		}

		a = X - Y * (Y - 1) / 2;

		if (Y % 2 == 0)
		{
			cout << a << '/' << Y - a + 1;
		}
		else
		{
			cout << Y - a + 1 << '/' << a;
		}
	}
}

1부터 n까지의 합을 구하는 식을 이용해 Y번째 줄까지의 총 개수를 구했다.

임시값 b가 X보다 커지면 Y를 찾은 것이었는데, b와 X가 같은 경우를 고려하지 않아서 한참 헤맸다.

+ Recent posts