Content - Bullet Pattern 유연성과 종류

담당자
이도현
상태
Reserve
시작-완료일
2024/03/18
예정 마감일
2024/03/20
완료일
2024/04/15

개요

수식 재사용 관련은 모두 GameMathUtils에 정적 메서드로 보관

GameMathUtils

탄퍼짐

public static Vector3 CalculateSpreadDirection(Vector3 originalDirection, float maxSpreadAngle, float concentration) { // 랜덤 각도를 계산 float spreadAngle = Random.Range(0, maxSpreadAngle/2.0f); spreadAngle *= Mathf.Lerp(1.0f, 0.0f, concentration); // 집중 정도에 따라 스케일 조정 // 랜덤 회전 축을 계산 (originalDirection에 수직인 벡터) Vector3 randomAxis = Vector3.Cross(originalDirection, Random.insideUnitSphere).normalized; // originalDirection을 랜덤 축으로 spreadAngle만큼 회전 Quaternion spreadRotation = Quaternion.AngleAxis(spreadAngle, randomAxis); Vector3 spreadDirection = spreadRotation * originalDirection; return spreadDirection.normalized; // 노멀라이즈된 조정된 방향 반환 }
C#
복사

일반적인 구형 패턴

// 구형 타입A(최상/최하단 채우기. 가장 일반적인 이미지.) public static List<Vector3> GenerateSpherePointsTypeA(int pointsPerLayer, int numberOfLayers, float distanceMultiplier) { // int pointsPerLayer : 한 층 둘레를 이룰 갯수 // int numberOfLayers : 층 수 // float distanceMultiplier : 거리계수 List<Vector3> spherePoints = new List<Vector3>(); for (int layerIndex = 0; layerIndex < numberOfLayers; layerIndex++) { float layerHeightRatio = (numberOfLayers == 1 ? 0 : layerIndex / (float)(numberOfLayers - 1)); for (int pointIndex = 0; pointIndex < pointsPerLayer; pointIndex++) { float theta = pointIndex * 2 * Mathf.PI / pointsPerLayer; // 둘레 방향 각도 float phi = layerHeightRatio * Mathf.PI; // 높이 방향 각도 spherePoints.Add(new Vector3( Mathf.Sin(phi) * Mathf.Sin(theta) * distanceMultiplier, Mathf.Cos(phi) * distanceMultiplier, Mathf.Sin(phi) * Mathf.Cos(theta) * distanceMultiplier )); if (layerIndex == 0 || layerIndex == numberOfLayers - 1) break; } } return spherePoints; }
C#
복사

리스트에 담긴 벡터를 전체회전, 스케일링 포함

// 전체 회전(아직 테스트 안 해봄) public static List<Vector3> RotateVectors(List<Vector3> originalVectors, Quaternion rotation, float distanceMultiplier) { // 벡터 집단에 대해 회전 및 거리계수를 곱함 List<Vector3> rotatedVectors = new List<Vector3>(); foreach (Vector3 originalVector in originalVectors) { // 회전 적용 및 거리 계수 적용 Vector3 rotatedVector = rotation * originalVector * distanceMultiplier; rotatedVectors.Add(rotatedVector); } return rotatedVectors; }
C#
복사

GIF

빨강 : 미사일 타입 - List<{시간, 움직임변경}> 느낌으로 적용하여 여러 움직임 타입을 연속하여 구사
군집, 회전
커스텀 입력 및 꼭지점 좌표 사이 직선 보간 정도 파라미터

3.25

Default(현위치), Muzzle(총구), Master, Root, Player
Out, To, Forward, Back
Completely Random
Spread(탄퍼짐)
Forward, LerpRot or LerpPos or LerpFixedPos, LerpTo~
등등의 요소를 조합한 모든 스테이터스에 대해 구현 해주어야 한다. 아직 누락된 부분이 많아서 부족한 현재의 Generator ㅠㅠ…
물론 Init 시점 말고, 움직임에 변화가 가해지는 시점에서도 생각해야한다.