In most films - especially in regards to the protagonist - really from the get-go they set up some scenario that endears that character to the audience. Or imbues him with some nobility or heroism or something. ↗
Sometimes a character is really based on research that you do. Other times it's just based on your imagination or perhaps your conversation with the director. Or sometimes all of the above. It depends on the movie and character. ↗