This project implements a 3D maze navigation system with smooth camera control, wall collision prevention, A* pathfinding, and automatic path-following.
The program displays both a main camera (left screen) and a top-down minimap (right screen), ensuring consistent camera orientation in both views.
- A / D keys — Rotate camera left/right (affects both main view and minimap camera)
- W / S keys — Move forward/backward, with wall collision prevention
- Q key — Use A* algorithm to find the shortest path to the goal and visualize it as a red line
- SpaceBar — Automatically move along the found path with smooth rotation at corners
The A* algorithm finds the shortest path from the start node to the goal node by minimizing:
f(n) = g(n) + h(n)
- g(n) — Actual cost from the start node to the current node
- h(n) — Estimated cost from the current node to the goal (Manhattan distance in this case)
- f(n) — Total estimated cost
- Used a
cameraYawvariable to store rotation angle - Converted angle to radians and updated
viewDirection - Both main view and minimap camera are rotated simultaneously
- Implemented
isCollision()to check if the target position is a wall - Movement is blocked if collision is detected
- Runs
Astar()to compute the shortest path from current position to the goal - Priority queue (Open List) for efficient smallest f-value extraction
- Closed List to store visited nodes
- Nodes store
(x, y, g, h, f, parent)
- Draw red cubes along the computed path
- Adjust size, position, and rotation for each segment
- Generated multiple intermediate points between key path nodes
- Used
Smoothstepto create smooth turns at corners - Controlled movement states: STOPPED → MOVING → PAUSED
- Movement resumes or restarts depending on state
- Issue: Initial A* implementation used simple vectors for open/closed lists without ordering by priority
- Effect: Sometimes failed to reach the goal in complex mazes
- Fix: Switched Open List to priority queue and added
parentattribute to Node for proper backtracking
- Issue: Pressing
Qquickly triggered multiple A* executions - Effect: Displayed duplicated path outputs
- Fix: Added logic to ensure a single execution per key press
- Issue: Early implementation set
cameraPosdirectly without generating intermediate points - Effect: Camera flickered or moved backward unexpectedly
- Fix: Precomputed and stored intermediate positions, directions, and angles, then iterated smoothly
- Issue: Short key presses were processed multiple times
- Effect: State changes occurred too quickly, causing incorrect behavior
- Fix: Used
GetAsyncKeyStateandspacePressedflag to handle one press at a time
