To further demonstrate that intent of the actor does not affect the morality of the act itself, I present this scenario:
An alternative version of the trolley scenario, where the trolley is on a path down track A with four innocent people tied to the tracks and facing certain death. The only option available to you is to pull a lever to divert the trolley down track B where only one person is tied to the tracks and not facing certain death, unless you do pull the lever. The difference here is that the person on track B is not an innocent person, but a mass murderer. While being tied to the tracks and unable to free himself, his hands are not restrained and he is holding a gun and shooting at a both you and a nearby crowd of innocent people.
If you as the actor decide to pull the level, your motive could be derived from variety of different intents…
Perhaps your intent is to save the four innocents on track A.
Maybe your intent is to save the people in the crowd being shot at by the person on track B.
Possibly your intent is to save your own life from the active threat against it presented by the person on track B.
It is also conceivable that your intent would be any combination of some or all three of these intents.
Or maybe it is the fact that you would like to catch the next scheduled trolley heading down track A, and not diverting the trolley would significantly hamper your ability to do so due to the cleanup and inevitable investigation that would occur if you had not switched the tracks.
Or maybe the guy tied to track B was a complete jerk to you in high school and you will derive much pleasure at watching his ultimate demise at the hands of the runaway trolley.
As you can see, the intent could be varied and can affect your moral culpability and whether you are a hero, or self-absorbed, or guilty of murder, but the morality of the act itself is not dependent on your intent.
The morality of the act is dependent on the directness of your action (pulling the lever will immediately result in the death of the person on track B), and your knowledge (that the person on track B is a mass murderer who is presently an active threat to innocent life).
Your intent, motivation, interior disposition, etc… do not change the morality of the act: It is moral to take an action that ends the life of someone who is actively presenting a threat to innocent life.
Your intent, motivation, interior disposition, etc… do however effect your moral culpability, for example whether your motive for the act is to save innocent life or to take revenge and settle a score.
It is possible to complete a morally good or morally neutral act and still be personally culpable for acting immorally based on your intentions.