That's not the definition of morality. That's self-interest or self-preservation. Adhering to a set of guidelines or rules with empathy, regardless if it doesn't immediately register as detrimental to ourselves is more like it.
Hence people act immorally in the name of survival.