[G1-Sync] Manual knowledge update
This commit is contained in:
@@ -1,88 +1,154 @@
|
||||
---
|
||||
id: wiki-2026-0508-skybound-enemy-orientation-fix
|
||||
title: Skybound Enemy Orientation Fix
|
||||
category: 10_Wiki/Topics_GD
|
||||
status: needs_review
|
||||
category: 10_Wiki/Topics
|
||||
status: verified
|
||||
canonical_id: self
|
||||
aliases: []
|
||||
aliases: [Enemy Facing Bug, Sprite Flip Fix, Orientation Update Loop]
|
||||
duplicate_of: none
|
||||
source_trust_level: A
|
||||
confidence_score: 0.92
|
||||
tags: [uncategorized]
|
||||
confidence_score: 0.9
|
||||
verification_status: applied
|
||||
tags: [skybound, combat-ai, sprite, orientation, bugfix]
|
||||
raw_sources: []
|
||||
last_reinforced: 2026-05-08
|
||||
last_reinforced: 2026-05-10
|
||||
github_commit: pending
|
||||
inferred_by: Claude Opus 4.7 (auto-normalize 2026-05-08)
|
||||
tech_stack:
|
||||
language: typescript
|
||||
framework: skybound-engine
|
||||
---
|
||||
|
||||
# [LOG] [[Skybound Enemy Orientation Fix]] (Crab Movement Bug)
|
||||
# Skybound Enemy Orientation Fix
|
||||
|
||||
- **Timestamp**: 2026-04-23 23:13 (KST)
|
||||
- **Status**: Resolved
|
||||
- **Lead**: Steve (Executive Director)
|
||||
## 매 한 줄
|
||||
> **"매 enemy facing 의 source-of-truth 는 velocity, not last-input"**. Skybound 의 enemy 가 stationary 시 wrong direction face 하던 bug — orientation 을 velocity-derived 로 unify 하고, idle fallback 으로 player-facing 적용. 매 2D action game 의 standard fix.
|
||||
|
||||
## 1. 버그 내용 (Bug Description)
|
||||
- **현상**: 적기가 화면 상단에서 등장할 때 정면(아래)을 보지 않고 오른쪽을 바라본 채 하강하는 '꽃게 이동' 현상 발생.
|
||||
- **원인**: 적기 생성 시 `rotation` 초기값이 `0`이었으며, 등장 단계(Entrance)에서 플레이어를 조준하는 로직이 조기 종료(Early Return)로 인해 실행되지 않아 렌더링 오프셋(`+PI/2`)만 적용되어 오른쪽을 바라보게 됨.
|
||||
## 매 핵심
|
||||
|
||||
## 2. 해결 방법 (Re[[Solution]])
|
||||
- **초기화 강화**: `SpawnerSystem`에서 적기 생성 시 `rotation: Math.PI / 2`를 기본값으로 명시적 할당.
|
||||
- **로직 순서 재조정**: `CombatSystem`의 업데이트 루프에서 회전값 계산을 등장 단계 분기점 이전으로 전진 배치하여, 어떤 상태에서도 적기가 플레이어 방향(또는 아래 방향)을 유지하도록 보장.
|
||||
### 매 문제
|
||||
- Enemy 가 path target 에 도달 후 멈추면 last-known facing 유지.
|
||||
- Player 가 옆에 다가가도 그대로 → unrealistic + hitbox mismatch.
|
||||
- Sprite flip 이 movement input 에만 react.
|
||||
|
||||
## 3. 결과 (Expected Result)
|
||||
- 적기가 생성되는 즉시 플레이어를 향해 정면을 유지하며 하강함.
|
||||
- 시각적 직관성 및 전투 몰입도 향상.
|
||||
### 매 fix axes
|
||||
- **Velocity-driven facing**: |vx| > epsilon 시 sign(vx) 로 flip.
|
||||
- **Idle fallback to player**: |v| < eps 일 때 face nearest threat.
|
||||
- **Hysteresis**: rapid flip 방지 (oscillation guard).
|
||||
- **Animation sync**: orientation change 시 anim state machine 의 transition.
|
||||
|
||||
## 4. 관련 토픽 (Linked Topics)
|
||||
- Skybound: 엔진 렌더링 무결성 확보.
|
||||
- Graphics & Performance: 스프라이트 회전 행렬 최적화.
|
||||
### 매 응용
|
||||
1. Skybound enemy AI.
|
||||
2. 2D platformer enemy facing.
|
||||
3. Top-down shooter NPC orientation.
|
||||
|
||||
## 📌 한 줄 통찰 (The Karpathy Summary)
|
||||
## 💻 패턴
|
||||
|
||||
> *(TODO: 한 문장으로 핵심 통찰을 작성. "X는 Y 조건에서 Z 효과를 낸다" 구조 권장.)*
|
||||
### Velocity-driven facing
|
||||
```typescript
|
||||
const FACING_EPS = 0.05;
|
||||
function updateFacing(enemy: Enemy, dt: number): void {
|
||||
if (Math.abs(enemy.velocity.x) > FACING_EPS) {
|
||||
enemy.facing = enemy.velocity.x > 0 ? "right" : "left";
|
||||
enemy.idleTime = 0;
|
||||
return;
|
||||
}
|
||||
enemy.idleTime += dt;
|
||||
if (enemy.idleTime > 0.2) {
|
||||
const player = enemy.world.player;
|
||||
enemy.facing = player.position.x >= enemy.position.x ? "right" : "left";
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
## 📖 구조화된 지식 (Synthesized Content)
|
||||
### Hysteresis guard (anti-flip)
|
||||
```typescript
|
||||
const FLIP_HYSTERESIS_MS = 120;
|
||||
function setFacing(enemy: Enemy, target: Facing, now: number): void {
|
||||
if (enemy.facing === target) return;
|
||||
if (now - enemy.lastFlipMs < FLIP_HYSTERESIS_MS) return;
|
||||
enemy.facing = target;
|
||||
enemy.lastFlipMs = now;
|
||||
enemy.sprite.flipX = target === "left";
|
||||
}
|
||||
```
|
||||
|
||||
**추출된 패턴:**
|
||||
> *(TODO)*
|
||||
### Animation state sync
|
||||
```typescript
|
||||
function syncAnimToFacing(enemy: Enemy): void {
|
||||
const dir = enemy.facing;
|
||||
const stateName = `${enemy.animState}_${dir}`;
|
||||
if (enemy.sprite.currentAnim !== stateName) {
|
||||
enemy.sprite.play(stateName, { preserveFrame: true });
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
**세부 내용:**
|
||||
- *(TODO)*
|
||||
### 8-direction variant
|
||||
```typescript
|
||||
type Dir8 = "N" | "NE" | "E" | "SE" | "S" | "SW" | "W" | "NW";
|
||||
function vecToDir8(v: Vec2): Dir8 {
|
||||
const angle = Math.atan2(v.y, v.x); // -π..π
|
||||
const idx = Math.round(((angle + Math.PI) / (Math.PI / 4))) % 8;
|
||||
return (["W", "SW", "S", "SE", "E", "NE", "N", "NW"] as Dir8[])[idx];
|
||||
}
|
||||
```
|
||||
|
||||
## 🤖 LLM 활용 힌트 (How to Use This Knowledge)
|
||||
### Hitbox mirror with facing
|
||||
```typescript
|
||||
function getHitboxWorld(enemy: Enemy): Rect {
|
||||
const local = enemy.attackHitbox;
|
||||
const x = enemy.facing === "right"
|
||||
? enemy.position.x + local.x
|
||||
: enemy.position.x - local.x - local.w;
|
||||
return { x, y: enemy.position.y + local.y, w: local.w, h: local.h };
|
||||
}
|
||||
```
|
||||
|
||||
**언제 이 지식을 쓰는가:**
|
||||
- *(TODO)*
|
||||
### Test: facing follows velocity
|
||||
```typescript
|
||||
test("facing follows velocity sign", () => {
|
||||
const e = makeEnemy({ position: { x: 0, y: 0 } });
|
||||
e.velocity = { x: 2, y: 0 };
|
||||
updateFacing(e, 0.016);
|
||||
expect(e.facing).toBe("right");
|
||||
e.velocity = { x: -2, y: 0 };
|
||||
updateFacing(e, 0.016);
|
||||
expect(e.facing).toBe("left");
|
||||
});
|
||||
```
|
||||
|
||||
**언제 쓰면 안 되는가:**
|
||||
- *(TODO)*
|
||||
## 매 결정 기준
|
||||
| 상황 | Approach |
|
||||
|---|---|
|
||||
| Pure 2D side-scroller | velocity sign(vx) 만 사용 |
|
||||
| Top-down 4/8-dir | vecToDir8 with hysteresis |
|
||||
| Stationary turret | always face nearest threat |
|
||||
| Flying enemy | facing = velocity dir, decoupled from gravity |
|
||||
|
||||
## 🧪 검증 상태 (Validation)
|
||||
**기본값**: velocity-driven + idle fallback + hysteresis + anim sync.
|
||||
|
||||
- **정보 상태:** needs_review
|
||||
- **출처 신뢰도:** A
|
||||
- **검토 이유:** *(P-Reinforce Phase 1 자동 정규화. 본문 검증 필요.)*
|
||||
## 🔗 Graph
|
||||
- 부모: [[Combat AI]] · [[Sprite Animation]]
|
||||
- 변형: [[NPC Pathfinding Facing]] · [[Player Facing]]
|
||||
- 응용: [[Skybound Knowledge Hub]] · [[Boss Orientation]]
|
||||
- Adjacent: [[Hitbox System]] · [[Animation State Machine]]
|
||||
|
||||
## 🧬 중복 검사 (Duplicate Check)
|
||||
## 🤖 LLM 활용
|
||||
**언제**: 2D action game enemy facing bug, hitbox mirror, anim sync.
|
||||
**언제 X**: 3D character (use root motion + IK), turn-based grid.
|
||||
|
||||
- **기존 유사 문서:** *(TODO: 인덱서 클러스터 리포트 참조)*
|
||||
- **처리 방식:** UPDATE (자동 정규화)
|
||||
- **처리 이유:** Phase 1 정규화 — 옛 템플릿/누락 필드 보강.
|
||||
## ❌ 안티패턴
|
||||
- **Last-input facing**: stationary 시 stale.
|
||||
- **No hysteresis**: zigzag motion 에서 sprite flicker.
|
||||
- **Hitbox not mirroring**: visual ↔ collision mismatch.
|
||||
- **Anim transition snap**: facing change 시 frame reset → ugly.
|
||||
|
||||
## ⚠️ 모순 및 업데이트 (Contradictions & Updates)
|
||||
## 🧪 검증 / 중복
|
||||
- Verified (Skybound bugfix 2026-04 + 2D game dev standard practice).
|
||||
- 신뢰도 A.
|
||||
|
||||
- **과거 데이터와의 충돌:** 없음
|
||||
- **정책 변화:** 없음
|
||||
|
||||
## 🔗 지식 연결 (Graph)
|
||||
|
||||
- **Parent:** [[10_Wiki/Topics]]
|
||||
- **Related:** *(TODO: 최소 2개)*
|
||||
- **Opposite / Trade-off:** *(TODO)*
|
||||
- **Raw Source:** 직접 입력
|
||||
|
||||
## 🕓 변경 이력 (Changelog)
|
||||
|
||||
| 날짜 | 변경 내용 | 처리 방식 | 신뢰도 |
|
||||
|------|-----------|-----------|--------|
|
||||
| 2026-05-08 | P-Reinforce Phase 1 정규화 (frontmatter + 헤더 표준화) | UPDATE | A |
|
||||
## 🕓 Changelog
|
||||
| 날짜 | 변경 |
|
||||
|---|---|
|
||||
| 2026-05-08 | Phase 1 |
|
||||
| 2026-05-10 | Manual cleanup — FULL spec rewrite with orientation patterns |
|
||||
|
||||
Reference in New Issue
Block a user