A real-time 2D interceptor simulation built with C++ and SFML, demonstrating proportional navigation for target tracking.
This project simulates a guided interceptor tracking and pursuing a moving target using proportional navigation guidance. The interceptor adjusts its trajectory based on the rate of change of the line-of-sight angle to the target, creating realistic pursuit behavior.
- Proportional Navigation: Implements a proportional navigation algorithm where the interceptor's turn rate is proportional to the line-of-sight angle rate
- Visual Trail Effects: Interceptor leaves a smoke trail showing its flight path
- Dynamic Target: Target bounces around the screen with randomized velocity
- Interactive Launch: Right-click to launch the interceptor toward the current target position
- Collision Detection: Simulation pauses when the interceptor reaches the target
- C++20 or later
- SFML 3.0+ (Graphics module)
# Clone the repository
git clone https://github.com/14yashh/target-simulator.git
cd target-simulator
# Build with g++:
g++ main.cpp -lsfml-graphics -lsfml-window -lsfml-system -o interceptor
# Run
./interceptorNote: This code uses SFML 3.0 features that require C++20. Most modern compilers default to C++20, but if you encounter issues, add -std=c++20 to the compile command.
- Right Click: Launch interceptor toward target (also randomizes target velocity)
- ESC: Close the window
- The simulation pauses when the interceptor hits the target
- Launch again with another right-click to restart
The interceptor uses proportional navigation guidance, a technique commonly used in guided systems. The key principle:
- Calculate the line-of-sight (LOS) angle from interceptor to target
- Measure the rate of change of this angle (dλ/dt)
- Command a turn rate proportional to this rate:
turn_rate = N × dλ/dt
When the LOS angle rate approaches zero, the interceptor is on a collision course with the target.
- Acceleration: 200 units/s²
- Max Speed: 400 units/s
- Navigation Constant: 4.0 (controls aggressiveness of turns)
.
├── .gitignore # Git ignore rules
├── main.cpp # Main application loop and event handling
├── interceptor.h # Interceptor class with guidance logic
├── target-simulator.gif # Demo animation
└── README.md # This file
The simulation runs at 60 FPS and uses delta time for frame-independent physics. The proportional navigation implementation includes angle wrapping to handle the discontinuity at ±180°, ensuring smooth guidance through all quadrants.
Built with SFML - Simple and Fast Multimedia Library
