[UE] SetCursorDir

KANTAM·2022년 4월 25일
0

Unreal Engine

목록 보기
9/11
void MyCharacter::SetCursorDir() {
	//note that the line 58-59 is seen pretty common on the internet to find the cursor porjection
	//onto the internet, however, they do not give me the right vector.
	//FVector CursorWorldLocation, CursorWorldDirection;
	//GetWorld()->GetFirstPlayerController()->DeprojectMousePositionToWorld(CursorWorldLocation, CursorWorldDirection);
	//=====================================================================//

	//gets location of the actor in the world
	FVector CurrLoc = this->GetActorLocation();

	// the right method of getting cursor location!!! note: i used the exact same method in the Epic Top Down Blueprint.
	FHitResult hitResult;
	GetWorld()->GetFirstPlayerController()->GetHitResultUnderCursorByChannel(UEngineTypes::ConvertToTraceType(ECC_Visibility), true, hitResult);
	FVector hitLoc = hitResult.Location;

	//geting the original rotation of the acter;
	FRotator newRot = this->GetActorRotation();
	//Using atan2 function to get the degree between our character location and cursor location
	// aka how much we want the character to rotate
	float newYaw = (hitLoc - CurrLoc).Rotation().Yaw;;
	//Using that degree as the Yaw(rotating around Z axis) of our Frotator
	newRot.Yaw = newYaw;

	//in the end, we set it;
	// this->GetController()->SetControlRotation(newRot);
	SetActorRotation(newRot);
}
  • Unreal Engine에서 캐릭터가 클릭한 곳을 바라보게 하는 함수

0개의 댓글