How would you build a third-person camera that follows the player smoothly and does not clip through walls?
What the interviewer wants to hear
- Orbit around a pivot near the character using yaw and pitch input
- Smooth position and rotation with frame-rate independent damping
- Sphere cast from pivot to desired position and pull the camera in on hits
- Run in LateUpdate after the character moves
- Handle edge cases: fading the character when too close, tuning values, Cinemachine
Model answer
I put a pivot at the character's shoulder or head height and orbit the camera around it with yaw and pitch from the look input, clamping pitch so it cannot flip. The desired position is pivot minus forward times distance. To avoid walls, I sphere cast from the pivot toward that position and, if it hits, move the camera to just before the hit point, pulling in fast and easing back out slowly so it does not pop. All of this runs in LateUpdate so the character has already moved, and smoothing uses exponential damping or SmoothDamp so it behaves the same at any frame rate. If the camera gets very close I fade the character out. In Unity I would often start from Cinemachine, which provides orbit and collider features already.
Can you answer it under time pressure?
Take a timed medium round and get scored on every answer.
More medium Game Developer questions
- Your game runs at 40 FPS but must hit 60 FPS. How do you find and fix the problem?
- How would you design a save game system?
- How would you build the AI for an enemy guard that patrols, notices the player, chases and attacks?
- How would you choose between Unity, Unreal and Godot for a new project?
- How do you make game systems easy for designers to tune without changing code?
- Players report that their character sometimes falls through the floor. How do you investigate and fix it?
- How would you design input handling that supports keyboard, gamepad and touch, plus key rebinding?
- How would you procedurally generate dungeon levels that are always playable?
- Describe how you would design a reusable object pool and what trade-offs it has.