A high-performance Unity system for recording and replaying player movements with ghost playback functionality
Unity Ghost Player System is a comprehensive movement recording and playback solution that enables you to create multiple ghost replays of player actions. Perfect for racing games, speedrunning, training modes, and any game that needs to show previous attempts or AI learning.
| Feature | Description |
|---|---|
| 🎬 Movement Recording | Records position, rotation, animation state, and input direction |
| 👻 Ghost Playback | Spawn unlimited ghost players that replay recorded movements |
| ⚡ Performance Optimized | Optional Unity Jobs System + Burst Compiler support |
| 🔄 Time Control | Adjustable speed, reverse playback, and seamless looping |
| 🪞 Mirror Mode | Horizontal flipping for competitive ghost comparisons |
| 🎨 Visual Customization | Customizable colors and transparency per ghost |
| ⏱️ Precise Synchronization | Drift correction for frame-perfect timing |
| 📊 Debug Tools | Built-in Gizmos and inspector controls |
1. PlayerController - Main player controller
Features:
- 8-directional movement snapping
- Jump mechanics with animation events
- Smooth rotation interpolation
- Unity Input System integration
Inspector Settings:
- Movement speed
- Jump configuration
- Rotation speed settings
2. MoveRecorder - Records player data
Features:
- Circular buffer implementation
- Fixed timestep recording
- Jobs System optimization
- Debug visualization
Inspector Settings:
- Buffer size (default: 600 frames)
- Jobs System toggle
- Burst Compiler option
3. GhostPlayer - Playback controller
Features:
- Smooth frame interpolation
- Time manipulation (speed/reverse/loop)
- Drift correction algorithm
- Mirror mode support
Inspector Settings:
- Time scale multiplier
- Playback delay
- Loop/reverse options
- Drift correction factor
4. GhostPlayerSpawner - Multi-ghost manager
Features:
- Batch spawning system
- Individual timing offsets
- Color randomization
- Mirror pattern configuration
Inspector Settings:
- Number of ghosts
- Spawn delays
- Color palette
- Mirror patterns
5. Jobs System - Performance optimization (Optional)
Components:
FrameInterpolationJob- Burst-compiled blend calculationBinarySearchJob- Optimized frame lookup
Performance Gains:
- Classic Mode: ~0.1-0.2ms per ghost
- Jobs Mode: ~0.05-0.1ms per ghost
- Unity 2021.3 or later
- Input System package
- Odin Inspector (optional - for enhanced editor UI)
-
Import Scripts
📁 Your Project └── 📁 Scripts └── 📁 Game └── 📁 Player ├── 📁 Scripts │ ├── PlayerController.cs │ ├── GhostPlayer.cs │ ├── GhostPlayerSpawner.cs │ └── 📁 Jobs │ └── FrameInterpolationJob.cs └── 📁 Recorder └── 📁 Scripts ├── MoveRecorder.cs ├── PlayerFrame.cs └── 📁 Jobs └── BinarySearchJob.cs -
Configure Player
- Attach
PlayerControllerto your player GameObject - Assign Input Action References
- Configure movement settings
- Attach
-
Setup Recording
- Add
MoveRecordercomponent - Assign the PlayerController reference
- Set buffer size (600 frames = ~10 seconds at 60fps)
- Add
-
Create Ghost Prefab
- Duplicate your player model
- Add
GhostPlayercomponent - Remove player input components
- Save as prefab
-
Configure Spawner
- Create empty GameObject
- Add
GhostPlayerSpawner - Assign recorder and ghost prefab references
// Recording starts automatically
// Access data programmatically:
public class GameManager : MonoBehaviour
{
[SerializeField] private MoveRecorder recorder;
[SerializeField] private GhostPlayer ghost;
void Start()
{
// Get recording info
float duration = recorder.GetRecordingDuration();
int frameCount = recorder.FrameCount;
Debug.Log($"Recorded {frameCount} frames over {duration}s");
// Control playback
ghost.Play();
ghost.SetTimeScale(2.0f); // 2x speed
}
}public class RaceManager : MonoBehaviour
{
[SerializeField] private GhostPlayerSpawner spawner;
void StartRace()
{
// Spawn 5 ghosts with 0.2s delay between each
spawner.SpawnAllGhosts();
spawner.PlayAllGhosts();
}
void ShowSlowMotion()
{
spawner.SetGhostTimeScale(0.5f); // Slow-mo replay
}
}// Precise timing control
ghostPlayer.SetPlaybackDelay(0.5f); // 500ms initial delay
ghostPlayer.SetDriftCorrection(0.1f); // Smooth synchronization
// Performance optimization
recorder.SetUseJobsSystem(true); // Enable burst compilation
ghostPlayer.SetUseJobsSystem(true);
// Visual effects
ghost.ColorComponent.SetColor(new Color(1, 0, 0, 0.5f)); // Red semi-transparent| Parameter | Description | Default |
|---|---|---|
| Target | PlayerController reference | Required |
| Max Frames | Buffer capacity | 600 |
| Use Jobs System | Enable performance mode | false |
| Use Burst Compiler | Compile with Burst | true |
| Parameter | Description | Range |
|---|---|---|
| Time Scale | Playback speed multiplier | 0.1 - 5.0 |
| Auto Play | Start on enable | bool |
| Loop Playback | Repeat continuously | bool |
| Reverse Playback | Play backwards | bool |
| Playback Delay | Initial delay (seconds) | 0 - 10 |
| Drift Correction | Sync strength | 0.0 - 1.0 |
| Mirror Mode | Horizontal flip | bool |
| Parameter | Description |
|---|---|
| Number of Ghosts | Count to spawn |
| Delay Between Ghosts | Stagger timing (seconds) |
| Playback Delay | Per-ghost offset |
| Randomize Colors | Use random palette |
| Ghost Colors | Color array |
| Mirror Pattern | Per-ghost mirror settings |
| Mode | Ghosts | Frame Time | CPU Usage |
|---|---|---|---|
| Classic | 5 | 0.8ms | Low |
| Classic | 10 | 1.5ms | Medium |
| Jobs + Burst | 5 | 0.4ms | Very Low |
| Jobs + Burst | 20 | 1.2ms | Low |
Recommendation: Use Jobs System for 10+ simultaneous ghosts
public struct PlayerFrame
{
public Vector3 position; // World position
public Quaternion rotation; // World rotation
public float normalizedAnimTime; // Animation time
public Vector2 moveDirection; // Input direction
public bool isJumping; // Jump state
public float time; // Relative timestamp
}Scene Visualization:
- 🟦 Cyan line: Recorded path
- 🟩 Green sphere: Start position
- 🟥 Red sphere: End position
Inspector Controls:
▶️ Play/Pause/Stop buttons- 🔄 Restart recording
- 🗑️ Clear buffer
Debug Information:
Buffer: 483/600 frames (80.5%) | Duration: 8.05s | Head: 483 | Mode: Jobs+Burst
- 🏁 Racing Games - Show previous lap ghosts
- 🎮 Speedrunning - Compare run attempts
- 🎓 Training Modes - Learn from recorded movements
- 🤖 AI Learning - Record and analyze behavior patterns
- 🎬 Replay Systems - Create cinematic replays
- 👥 Multiplayer - Asynchronous ghost competitions
- Network synchronization support
- Save/load recordings to disk
- Ghost interpolation quality settings
- Advanced animation blending
- Ghost prediction system
This project is free to use and modify for personal and commercial projects.
Contributions are welcome! Please feel free to submit a Pull Request.
- Fork the repository
- Create your feature branch (
git checkout -b feature/AmazingFeature) - Commit your changes (
git commit -m 'Add some AmazingFeature') - Push to the branch (
git push origin feature/AmazingFeature) - Open a Pull Request
- Issues: GitHub Issues
- Discussions: GitHub Discussions
Give a ⭐️ if this project helped you!
Unity Ghost Player System, oyuncu aksiyonlarının birden fazla hayalet tekrarını oluşturmanızı sağlayan kapsamlı bir hareket kaydetme ve oynatma çözümüdür. Yarış oyunları, speedrun, eğitim modları ve önceki denemeleri veya yapay zeka öğrenimini göstermesi gereken her oyun için mükemmeldir.
| Özellik | Açıklama |
|---|---|
| 🎬 Hareket Kaydı | Pozisyon, rotasyon, animasyon durumu ve giriş yönünü kaydeder |
| 👻 Hayalet Oynatma | Kaydedilen hareketleri tekrar oynatan sınırsız hayalet oyuncu oluşturur |
| ⚡ Performans Optimize | İsteğe bağlı Unity Jobs System + Burst Compiler desteği |
| 🔄 Zaman Kontrolü | Ayarlanabilir hız, geri oynatma ve kesintisiz döngü |
| 🪞 Ayna Modu | Rekabetçi hayalet karşılaştırmaları için yatay çevirme |
| 🎨 Görsel Özelleştirme | Hayalet başına özelleştirilebilir renkler ve şeffaflık |
| ⏱️ Hassas Senkronizasyon | Kare mükemmel zamanlama için sapma düzeltme |
| 📊 Hata Ayıklama Araçları | Yerleşik Gizmos ve inspector kontrolleri |
1. PlayerController - Ana oyuncu kontrolcüsü
Özellikler:
- 8 yönlü hareket yakalama
- Animasyon olaylarıyla zıplama mekaniği
- Yumuşak rotasyon interpolasyonu
- Unity Input System entegrasyonu
Inspector Ayarları:
- Hareket hızı
- Zıplama yapılandırması
- Rotasyon hızı ayarları
2. MoveRecorder - Oyuncu verilerini kaydeder
Özellikler:
- Dairesel tampon uygulaması
- Sabit zaman adımı kaydı
- Jobs System optimizasyonu
- Debug görselleştirme
Inspector Ayarları:
- Tampon boyutu (varsayılan: 600 kare)
- Jobs System açma/kapama
- Burst Compiler seçeneği
3. GhostPlayer - Oynatma kontrolcüsü
Özellikler:
- Yumuşak kare interpolasyonu
- Zaman manipülasyonu (hız/geri/döngü)
- Sapma düzeltme algoritması
- Ayna modu desteği
Inspector Ayarları:
- Zaman ölçeği çarpanı
- Oynatma gecikmesi
- Döngü/geri seçenekleri
- Sapma düzeltme faktörü
4. GhostPlayerSpawner - Çoklu hayalet yöneticisi
Özellikler:
- Toplu oluşturma sistemi
- Bireysel zamanlama ofsetleri
- Renk rastgeleleştirme
- Ayna deseni yapılandırması
Inspector Ayarları:
- Hayalet sayısı
- Oluşturma gecikmeleri
- Renk paleti
- Ayna desenleri
5. Jobs System - Performans optimizasyonu (İsteğe Bağlı)
Bileşenler:
FrameInterpolationJob- Burst-derlenmiş karışım hesaplamaBinarySearchJob- Optimize edilmiş kare arama
Performans Kazançları:
- Klasik Mod: Hayalet başına ~0.1-0.2ms
- Jobs Modu: Hayalet başına ~0.05-0.1ms
- Unity 2021.3 veya üzeri
- Input System paketi
- Odin Inspector (isteğe bağlı - gelişmiş editör UI için)
-
Scriptleri İçe Aktar
📁 Projeniz └── 📁 Scripts └── 📁 Game └── 📁 Player ├── 📁 Scripts │ ├── PlayerController.cs │ ├── GhostPlayer.cs │ ├── GhostPlayerSpawner.cs │ └── 📁 Jobs │ └── FrameInterpolationJob.cs └── 📁 Recorder └── 📁 Scripts ├── MoveRecorder.cs ├── PlayerFrame.cs └── 📁 Jobs └── BinarySearchJob.cs -
Oyuncuyu Yapılandır
PlayerController'ı oyuncu GameObject'inize ekleyin- Input Action Referanslarını atayın
- Hareket ayarlarını yapılandırın
-
Kaydı Kur
MoveRecorderbileşenini ekleyin- PlayerController referansını atayın
- Tampon boyutunu ayarlayın (600 kare = 60fps'de ~10 saniye)
-
Hayalet Prefab Oluştur
- Oyuncu modelinizi kopyalayın
GhostPlayerbileşenini ekleyin- Oyuncu giriş bileşenlerini kaldırın
- Prefab olarak kaydedin
-
Spawner'ı Yapılandır
- Boş GameObject oluşturun
GhostPlayerSpawnerekleyin- Recorder ve hayalet prefab referanslarını atayın
// Kayıt otomatik başlar
// Verilere programatik erişim:
public class GameManager : MonoBehaviour
{
[SerializeField] private MoveRecorder recorder;
[SerializeField] private GhostPlayer ghost;
void Start()
{
// Kayıt bilgisini al
float duration = recorder.GetRecordingDuration();
int frameCount = recorder.FrameCount;
Debug.Log($"{frameCount} kare, {duration} saniye içinde kaydedildi");
// Oynatmayı kontrol et
ghost.Play();
ghost.SetTimeScale(2.0f); // 2x hız
}
}public class RaceManager : MonoBehaviour
{
[SerializeField] private GhostPlayerSpawner spawner;
void StartRace()
{
// Her biri arasında 0.2s gecikme ile 5 hayalet oluştur
spawner.SpawnAllGhosts();
spawner.PlayAllGhosts();
}
void ShowSlowMotion()
{
spawner.SetGhostTimeScale(0.5f); // Ağır çekim tekrar
}
}// Hassas zamanlama kontrolü
ghostPlayer.SetPlaybackDelay(0.5f); // 500ms başlangıç gecikmesi
ghostPlayer.SetDriftCorrection(0.1f); // Yumuşak senkronizasyon
// Performans optimizasyonu
recorder.SetUseJobsSystem(true); // Burst derlemeyi etkinleştir
ghostPlayer.SetUseJobsSystem(true);
// Görsel efektler
ghost.ColorComponent.SetColor(new Color(1, 0, 0, 0.5f)); // Yarı saydam kırmızı| Parametre | Açıklama | Varsayılan |
|---|---|---|
| Target | PlayerController referansı | Gerekli |
| Max Frames | Tampon kapasitesi | 600 |
| Use Jobs System | Performans modunu etkinleştir | false |
| Use Burst Compiler | Burst ile derle | true |
| Parametre | Açıklama | Aralık |
|---|---|---|
| Time Scale | Oynatma hızı çarpanı | 0.1 - 5.0 |
| Auto Play | Etkinleştiğinde başlat | bool |
| Loop Playback | Sürekli tekrarla | bool |
| Reverse Playback | Geri oynat | bool |
| Playback Delay | Başlangıç gecikmesi (saniye) | 0 - 10 |
| Drift Correction | Senkronizasyon gücü | 0.0 - 1.0 |
| Mirror Mode | Yatay çevirme | bool |
| Parametre | Açıklama |
|---|---|
| Number of Ghosts | Oluşturulacak sayı |
| Delay Between Ghosts | Kademeli zamanlama (saniye) |
| Playback Delay | Hayalet başına offset |
| Randomize Colors | Rastgele palet kullan |
| Ghost Colors | Renk dizisi |
| Mirror Pattern | Hayalet başına ayna ayarları |
| Mod | Hayalet | Kare Süresi | CPU Kullanımı |
|---|---|---|---|
| Klasik | 5 | 0.8ms | Düşük |
| Klasik | 10 | 1.5ms | Orta |
| Jobs + Burst | 5 | 0.4ms | Çok Düşük |
| Jobs + Burst | 20 | 1.2ms | Düşük |
Öneri: 10+ eşzamanlı hayalet için Jobs System kullanın
public struct PlayerFrame
{
public Vector3 position; // Dünya pozisyonu
public Quaternion rotation; // Dünya rotasyonu
public float normalizedAnimTime; // Animasyon zamanı
public Vector2 moveDirection; // Giriş yönü
public bool isJumping; // Zıplama durumu
public float time; // Göreceli zaman damgası
}Sahne Görselleştirme:
- 🟦 Cyan çizgi: Kaydedilen yol
- 🟩 Yeşil küre: Başlangıç pozisyonu
- 🟥 Kırmızı küre: Bitiş pozisyonu
Inspector Kontrolleri:
▶️ Play/Pause/Stop butonları- 🔄 Kaydı yeniden başlat
- 🗑️ Tamponu temizle
Debug Bilgisi:
Buffer: 483/600 kare (%80.5) | Süre: 8.05s | Head: 483 | Mod: Jobs+Burst
- 🏁 Yarış Oyunları - Önceki tur hayaletlerini göster
- 🎮 Speedrun - Koşu denemelerini karşılaştır
- 🎓 Eğitim Modları - Kaydedilen hareketlerden öğren
- 🤖 Yapay Zeka Öğrenimi - Davranış kalıplarını kaydet ve analiz et
- 🎬 Tekrar Sistemleri - Sinematik tekrarlar oluştur
- 👥 Çok Oyunculu - Asenkron hayalet yarışmaları
- Ağ senkronizasyonu desteği
- Kayıtları diske kaydet/yükle
- Hayalet interpolasyon kalite ayarları
- Gelişmiş animasyon karıştırma
- Hayalet tahmin sistemi
Bu proje kişisel ve ticari projeler için kullanmak ve değiştirmek ücretsizdir.
Katkılar memnuniyetle karşılanır! Lütfen Pull Request göndermekten çekinmeyin.
- Depoyu fork edin
- Feature branch'inizi oluşturun (
git checkout -b feature/HarikaOzellik) - Değişikliklerinizi commit edin (
git commit -m 'Harika özellik eklendi') - Branch'e push yapın (
git push origin feature/HarikaOzellik) - Pull Request açın
- Sorunlar: GitHub Issues
- Tartışmalar: GitHub Discussions
Bu proje size yardımcı olduysa bir ⭐️ bırakın!
Made with ❤️ for Unity Developers