Why are humans almost always portrayed as good in science fiction?

I'll explain this with an example. But first off I want to tell you that I mean no offense and no harm while saying this and you don't have to take it personally.
Now consider for a moment that your dad is a drunken sod. He drinks like a fish but he isn't abusive to your mother. Your mom on the other hand sits on the couch like a python watching the TV all day long but she cares for you and behaves with you normally with normal magnitude of affection like other mothers do with their kids. So basically even if you don't have an ideal family with the best traits, you guys are generally happy and content.
Now if it's your parents wedding anniversary and you are going to gift them a family painting, would you paint your father with a bottle of whiskey or your mother in front of the TV? No. You would focus on the better things and traits and try to picture them that way. You do this because you are programmed to paint the optimistic side. Because it gives you hope and makes you think that it would also make your parents happy.
That is what writers do. They portray humans as the good ones because they hope it would send out a strong message. Might as well inspire people. And they don't plan it. It happens subconsciously which means our race isn't so hopeless yet. We don't have to try prompting humans and their good-heartedness.
It's not about others being portrayed as the bad ones. It's just about us. It always is.

They aren't. The easiest examples off the of of my head are Avatar, Ender's Game and Starship Troopers.

In Avatar humans are imperialistic/manifest destiny wielding invaders.

In Ender's Game, even though the aliens attacked first accidentally, humanity continued to pursue them until they destroyed their homeworld and civilization without ever trying to figure out a way to communicate with the aliens.

Starship Troopers is the same way. Humans are aggressively anti xenomorphic.

Another example is the sci fi universe of warhammer 40,000. Set 40,000 years in the future, humanity has become a strange Roman like society called the Imperium of Man, that is extremely racist and believes all aliens should be exterminated to the point of incorporating the belief into a religion. Humanity has a galactic crusade to purge all aliens from the galaxy, anything non-human is considered heretical. The Imperium destroys entire planets along with its human inhabitants if they consider it to have become ‘unclean' using Exterminatus.

It's easier to sympathize with someone that looks like you. Hence, movies such as what you're describing take the easy way out by making the humans look better in comparison with the aliens. This way the audience has someone to connect with.

But not all science fiction is like that. District 9 is a great movie that puts a different spin on alien invasion. It also puts into perspective a lot of social and political problems that are relevant in this day and age.

I guess Avatar is also a relavent example, but at the end of the day it is a human who ends up saving the day.

Also, movies that make humans the good guys are generally blockbusters and feel good movies that want you to root for your own team.

It's like watching sports. You don't have to think too much about it. There's a formula: invasion, humans stuck against the wall, there's a hero with a do or die plan, execute the plan, looks like it's not gonna work but at the 11th hour it works and everyone cheers (including the audience). No matter how crappy the movie is, as an audience you'll feel a sense of joy and excitement watching  your human team triumph. It's a sneaky way of psychologically tricking you into thinking the movie was a good movie!

Hope that helps. Go team!

I imagine it's the same reason that, in United States movies, the bad guys are 'always' foreigners. We fear/dislike the 'other' and like ourselves.

Futuristic sci-fi in particular also often comes with the notion that we as a species have advanced beyond the petty infighting we so often engage in now.

It's like the plot in Watchmen--once we have a greater enemy than each other, we band together. At least that's the idea.

Of course there are examples of evil/cowardly humans in sci-fi. (The Matrix has Cypher who defects to the machines, and Avatar, awful as it is, portrays the humans as the antagonists. And there's still The Fifth Element, which has evil humans and good aliens.)

But, in general, once it's us v. them, we tend to like 'us.' I imagine that once we have more multiverse stories outside of comics, we'll notice how often it's our good universe v. their bad one.

Some of the best writers are optimists. Not much fun reading about how awful you are. Take Gene Roddenberry for example or Asimov. They both write about positive human development and technological advancement. We all want to see the future, theirs is bright and filled with outside dangers to humans. Star Trek tv series for example, the antagonist is nearly always an outside alien force that needs to be overcome and rarely ever an internal interpersonal conflict that isn't caused by an outside alien force. Bright and shiney future for humans who must overcome outside forces is fun to read. Even JR Tolken made his bad guys less than human or at the will or under the control of something unhuman. Golem, in that example was human until faced with an unnatural force that literally made an unrecognizable monster.

I imagine it has something to do with humanity's innate fear of things we don't understand. The average person, upon learning that intelligent extraterrestrial life really does exist, would be at least a little scared by the news, if not completely terrified. Nobody knows what intelligent aliens would think or want, or if they would be friendly or hostile upon making contact with us.

Since aliens are an unknown, and therefore scary, they often default to being the enemies in science fiction-the "bad guys." To make for an interesting story, the main characters-the humans-then naturally become the "good guys." The "humans vs. aliens" plot device, in many cases, is simply a reworking of the classic "good vs. evil" plot device that's been used in so many stories throughout history.

Humans in science fiction aren't always portrayed as "noble and selfless," though. Check out Battlestar Galactica (the reboot version). Sure, the Cylons are hostile and destructive, but only because they were made by humans, who simply passed on their own destructive tendencies to their creations. Most of the human main characters in the show say and do some pretty nasty things to each other, even as they fight a war for humanity's survival. This leads to a question that becomes a theme of the show: "Are we really worthy of survival?"

Which automobile company is innovative in manufacturing electric sports car? Is it Tesla or someone else?

IMHO it is not TESLA, there are many companies which are doing a great job in manufacturing a electric super cars, RIMAC CONCEPT ONE , NIO EP9 (MEGA CAR)When it comes to technology Rimac has lot of patents , even nio is the fastest autonnomus super car.check out the complete info

Are parallel universes real?

The theory of Parallel Universe or the Multi-verse is a hypothetical content stated by few Scientists. Not all of them believed this phenomenon but some of them do. The theory states that there could be another Universe on the other side of the the Universe which we know now. Where the

Is the sun heating up the earth?

Actually incoming solar radiation isn't even close to the amount of outgoing radiation emitted by the earth. The diagram below might provide some insight.