Do you know your main character inside and out? Can you tell your protagonist’s life story? To understand your character and keep them in consistently in character, you should know all about them.
Start with some basics. You should know what they look like. What’s their hair colour? Eye colour? Any identifying features? Height? Body type? Facial hair? Age?
You should know their personality. What would they do in certain situations? What do they like? What are their hobbies? Is there a word or phrase they like to use? What’s their daily routine? What do they like to eat? What do they hate? What makes them sick? What are they afraid of? What are their dreams?
You need to know their friends and enemies. You need to know their coworkers and family members. You need to know their pets.
You need to know what their job is. If they don’t work, are they studying? What are they doing at the moment?
Then go back to the beginning. Go through their life and figure out major life events, including birthplace, birthdate, what kind of home they grew up in, if they had good birthdays, where they went to school, who their friends were, who was influential in their youth, if they moved around from place to place, if they got in trouble, if they were good in school, if they had any part-time jobs, if they fell in love, if and when they lost their virginity, old injuries, traumatic events, where they went to university, if they traveled, if they got married, if they had children, their work history, and so on.
That’s a lot to think about. Now that you’ve done your protagonist, do the same for your antagonist and supporting characters. That’s a lot, isn’t it?
Keep all of this in a well-organised notebook that you can refer to quickly when you need to. This will keep your characters consistent and realistic.
I really need to do this myself. Any other bits of information you suggest?