This commit is contained in:
2026-04-08 12:22:36 +07:00
parent 13d271ded4
commit 1ae5446a5a

175
README.md
View File

@@ -140,106 +140,75 @@ Hệ thống điều khiển nhân vật không chỉ quản lý hành động m
stateDiagram-v2 stateDiagram-v2
direction TB direction TB
%% Định nghĩa các vùng trạng thái
state "🌸 GROUND LOCOMOTION" as Ground { state "🌸 GROUND LOCOMOTION" as Ground {
[*] --> Idle [*] --> Idle
state Idle { state Idle {
direction LR I_P: 📝 Vel < 0.1m/s
I_Phys: 📝 Vel < 0.1m/s I_C: 🌡️ Breathing (0.5Hz)
I_Cam: 🌡️ Breathing Cycle (0.5Hz)
} }
Idle --> Moving: "Input.mag > 0.1" Idle --> Moving : "Input.mag > 0.1"
state Moving { state Moving {
direction LR M_P: 👟 Speed 2-4m/s
M_Phys: 👟 Speed 2-4m/s M_C: 🎢 Head Bob (1.2Hz)
M_Cam: 🎢 Head Bob (1.2Hz)
} }
Moving --> Sneaking: "OnSneak (Hold)" Moving --> Sneaking : "OnSneak (Hold)"
state Sneaking { state Sneaking {
direction LR Sn_P: 🤫 Noise -50%
Sn_Phys: 🤫 Speed 1.5m/s | Noise -50% Sn_C: 📉 Lower Height
Sn_Cam: 📉 Height -0.5m | FOV 55
} }
Moving --> Sprinting: "OnSprint (Hold) 🔥" Moving --> Sprinting : "OnSprint (Hold)"
state Sprinting { state Sprinting {
direction LR Sp_P: ⚡ Speed > 6.5m/s
Sp_Phys: ⚡ Speed > 6.5m/s | Noise +100% Sp_C: 🌈 Dynamic FOV
Sp_Cam: 🌈 Dynamic FOV (60-85)
} }
Sprinting --> Moving: "Stamina == 0 or Release" Sprinting --> Moving : "Stamina Empty"
Sneaking --> Moving: "Release Sneak" Sneaking --> Moving : "Release Sneak"
} }
state "☁️ AIRBORNE & IMPACT" as Air { state "☁️ AIRBORNE & IMPACT" as Air {
state Jump { state Jump {
J_Phys: 🆙 AddForce Up J_P: 🆙 AddForce Up
J_Cam: 🚀 Instant Y-Kick
} }
state Falling { state Falling {
F_Phys: 📉 Gravity x 1.5 F_P: 📉 Gravity x 1.5
F_Cam: 💨 Wind Distortion VFX
} }
state Landing { state Landing {
L_Phys: 📏 Impact Velocity Check L_P: 📏 Impact Check
L_Cam: 💢 Screen Shake
} }
Jump --> Falling: "Velocity.y < 0" Jump --> Falling : "Vel.y < 0"
Falling --> Landing: "IsGrounded == true" Falling --> Landing : "IsGrounded == true"
} }
state "🎀 UTILITY & ACTIONS" as Utility { state " ACTION LAYER" as Utility {
state Dashing { state Dashing {
D_Phys: 💨 Burst 15m/s D_P: 💨 Burst 15m/s
D_Cam: 🍭 Lens Distortion
} }
state Interacting { state Interacting {
Int_Phys: 🔒 Root Motion Lock Int_P: 🔒 Root Motion Lock
Int_Cam: 👁️ Contextual Look-at
} }
} }
state "🌐 NETWORK SYNC (Fusion)" as Net { state "🌐 NETWORK SYNC" as Net {
state InputAuthority { state "Input Authority" as IA
IA: 🎮 Local Prediction state "State Authority" as SA
IA: ⏳ Buffer Tick N IA --> SA : "Send [Networked] Rotation"
} SA --> IA : "Reconciliation if Error"
state StateAuthority {
SA: 🖥️ Server Snapshot
SA: 🛠️ Reconciliation
}
IA --> SA: "[Networked] CamRotation"
SA --> IA: "Correction if Error > 0.5m"
} }
state "🎭 ROLE VIEWPORTS" as Roles { %% Transitions chính - Đã sửa lỗi tại đây ✨
state Seeker_FPS { Ground --> Air : "IsGrounded == false"
S_View: 🔦 1st Person POV Air --> Ground : "OnLand Event"
S_Logic: 🔊 Noise Meter UI Ground --> Utility : "OnAbilityTrigger"
} Utility --> Ground : "Action Complete"
state Trapper_STRAT {
T_View: 🗺️ Tactical Overlay
T_Logic: 🌡️ Heatmap & CCTV
}
}
%% Transitions chính (Đã sửa lỗi cú pháp bằng dấu "") note left of Ground : ✨ Sync: Velocity, MoveState
Ground --> Air: "!IsGrounded (Coyote Time: 0.2s)" note right of Net : ⚙️ Fusion: FixedUpdateNetwork
Air --> Ground: "OnLand Event ✨"
Ground --> Utility: "OnAbilityTrigger ⚡"
Utility --> Ground: "Action Complete ✅"
note left of Ground: 🎵 Sync: Velocity, MoveState
note right of Net: ⚙️ Fusion: FixedUpdateNetwork Loop
``` ```
### 2. Environment Scanner & Interaction ### 2. Environment Scanner & Interaction
@@ -327,64 +296,52 @@ Sử dụng **Photon Fusion (State Sync)** với cơ chế Client-Side Predictio
sequenceDiagram sequenceDiagram
autonumber autonumber
%% Định nghĩa các bên tham gia với phong cách đáng yêu participant IR as 🖱️ Input
participant IR as 🖱️ Input Reader box #E3F2FD "CLIENT"
box "🌸 CLIENT (Authority)" #E3F2FD participant CP as 🎀 Local Player
participant CP as 🎀 Local Player<br/>(Predictive)
end end
box "🌐 NETWORK" #FFF3E0 box #FFF3E0 "NET"
participant NT as ✨ Fusion Buffer participant NT as ✨ Fusion
end end
box "🖥️ SERVER" #E8F5E9 box #E8F5E9 "SERVER"
participant S as 👑 State Authority participant S as 👑 Authority
end end
box "👥 OTHERS" #F3E5F5 box #F3E5F5 "OTHERS"
participant RP as 🍭 Remote Proxies participant RP as 🍭 Proxies
end end
%% --- GIAI ĐOẠN 1: THU THẬP --- Note over IR, CP: [TICK N] Thu thập Input ✨
Note over IR, CP: [TICK N] Thu thập năng lượng Input ✨ IR->>CP: OnMove / OnJump
IR->>CP: OnMove / OnJump Events CP->>CP: 📦 Pack NetworkInputData
CP->>CP: 📦 Encode NetworkInputData
%% --- GIAI ĐOẠN 2: DỰ ĐOÁN --- rect rgb(255, 250, 240)
rect rgb(255, 245, 230) Note over CP, NT: Prediction Mode 🚀
Note over CP, NT: [FixedUpdateNetwork] Chạy trước tương lai! 🚀 CP->>CP: 🏃 Client-Side Prediction
CP->>CP: 🏃 Client-Side Prediction<br/>(Di chuyển ngay lập tức) CP->>NT: ✉️ Send Packet
CP->>NT: ✉️ Send Input Packet NT-->>S: UDP Transport
NT-->>S: Transport via UDP
end end
%% --- GIAI ĐOẠN 3: XÁC THỰC --- rect rgb(240, 255, 240)
rect rgb(235, 255, 235) Note right of S: SERVER VALIDATION ⚖️
Note right of S: SERVER LOGIC (Tick N) ⚖️ S->>S: 📝 Check Collision & Move
S->>S: 📝 Verify Input & Collision S->>S: 💾 Update [Networked] State
S->>S: 💾 Update [Networked] States
end end
%% --- GIAI ĐOẠN 4: ĐỒNG BỘ --- S-->>NT: 📣 Broadcast Snapshot
S-->>NT: 📣 Broadcast State Snapshot
par 💫 Hồi đáp Local Player par 💫 To Local
NT-->>CP: State Snapshot NT-->>CP: Snapshot
Note over CP: 🔄 RECONCILIATION Note over CP: 🔄 RECONCILE
alt ⚠️ Sai lệch > Threshold and 🌈 To Proxies
CP->>CP: Hard Snap & Resimulate NT-->>RP: Snapshot
else ✅ Hợp lệ Note over RP: 🎞️ INTERPOLATE
CP->>CP: Tiếp tục Simulation mượt mà
end
and 🌈 Cập nhật cho mọi người
NT-->>RP: State Snapshot
Note over RP: 🎞️ INTERPOLATION
RP->>RP: Lerp(Snap_N, Snap_N-1)
end end
%% --- GIAI ĐOẠN 5: HIỂN THỊ --- rect rgb(250, 245, 255)
rect rgb(250, 240, 255) Note over CP, RP: [LateUpdate] Rendering 🎨
Note over CP, RP: [LateUpdate] Rendering Kawaii VFX 🎨 CP->>CP: Camera Shake
CP->>CP: Cam Shake & Particles RP->>RP: Smooth Mesh Lerp
RP->>RP: Smooth Mesh Movement end
end
``` ```
--- ---