The key is the direction of the ball doesn’t actually matter. It’s either having 2 players between the attacker and the goal or, the attacker being behind the ball.
Imagine Erling is stood on the goal line, in the middle of the goal. Foden intercepts a pass from the keeper, then runs at the keeper, goes round him and gets to the by line. He then crosses the ball, backwards, a couple of yards from goal. Erling moves backwards 2 yards, gets the ball and scores. No goal as he’s offside.
Same scenario, but Erling is on the penalty spot. Not offside, goal given.