I have done a lot of things on the game these past few weeks. Instead of writing an enormous (or not) blog post showcasing all the features, I'll write some smaller ones, where I will take time to explain how I implemented them.
Today's post will be about the camera setup I have finally implemented recently.
First, here is how the camera behave before:
As you can see, it's a pretty basic implementation. The camera is on a rail, and follow the ball alongside the ground.
What I wanted is the camera to favor the view for the attacking team. When a player has the ball in hand, or is dribbling, I wanted the camera to show more room between the player and the hoop he is moving to, so the player can see the rim faster when he crosses the mid line.
Here is the result so far
In addition to what I said before, the camera now also does a better job at moving in depth with the player.
The camera slightly tilts down when the player is on the bottom of the court, and zooms a bit when he is on the far side of the court.
I'm pretty happy with the result so far, and I think it is a good starting point.
To implement this camera, I created a few curve float structures in the editor:
- 3 curves to set each of the components of the camera location, based on the target (the ball, or the player with the ball) position. This allows me to make the camera move faster toward the attacking hoop than the targeted actor. Also, it allows me to restrict the bound of the camera movement on the vertical and depth axis, before I make the camera pitch or zoom.
- 2 curves to set the pitch of the camera, based on the distance of the player to the camera, and the vertical position of the player. The pitch of the camera is configured to has the value of -20° by default. But the more the camera target moves closer to the camera, the more the pitch is decreased. The minimum pitch value in this case is around -23°. This may seem little, but I experienced with higher values and didn't find the result convincing. The vertical position of the camera target only influences the pitch of the camera when it is pretty high in the air, like for example when the player is doing a NBA-Jam like dunk. It helps to focus more on the action.
- 2 curves to set the FOV of the camera, also based on the distance to the camera, and the vertical position of the camera target. This allows me to zoom a little when the target is at the other side of the court, and also when the target has a high Z value.
All in all, this is a pretty basic implementation, and I'm pretty happy with the results. It sure needs some tweaking but it's a good starting point.