Jazz center Rudy Gobert faced little resistance against the Knicks last Wednesday, dunking on them every chance he got. After one slam, Knicks coach Jeff Hornacek screamed to Willy Hernangomez, “Foul him!”

Three nights later in San Antonio, Hornacek found himself saying the same thing to Hernangomez with Pau Gasol and LaMarcus Aldridge having their way on the Knicks inside.

Hernangomez has been better than expected, a reliable offensive contributor, whose game and importance have grown with Joakim Noah injured and now facing a 20-game ban for violating the NBA’s anti-drug policy. But Hernangomez knows he needs to improve defensively, and either challenge shots or foul someone to avoid an easy basket.

“I have to be way more focused on defense,” Hernangomez said after scoring a career-high 24 points with 13 rebounds in Saturday’s 106-98 loss to the Spurs. “I think from the beginning of the season right now I improved my defense, but it’s not enough.

“One of the biggest things I have to work this summer is going to be my defense so next year I can defend [centers] and [power forwards].”

The rookie center from Spain has been a bright spot for the Knicks, who began Sunday with a magic number of two for being eliminated from the playoffs for the fourth straight year. Hernangomez’s quick development has the Knicks and their fans envisioning a long-lasting frontcourt tandem of Kristaps Porzingis and Hernangomez.

advertisement | advertise on newsday

Hornacek said the Knicks, who host the Pistons Monday, initially thought Hernangomez, 22, would gain experience in the D-League. But he showed right away he could play. Hernangomez has an array of offensive moves. He showcased them against the Spurs and his idol Gasol en route to his first 20-point NBA game.

“He’s getting better and better every game he plays,” Hornacek said. “Pau and LaMarcus and Dewayne Dedmon, those are long, long guys. You see how smart a player he is. He didn’t try to jump over them and try to challenge them. He just shot his little floaters over those guys. He battled on the rebounds.”

But Hornacek acknowledged that Hernangomez, who is averaging 7.5 points and 6.8 rebounds, could have been more assertive defensively and not allow easy baskets.

“There were a couple of plays that because he had two fouls he didn’t want to foul,” Hornacek said. “We told him, ‘Hey you just got to go for it — if you foul you foul.’ That’s all right. Other guys will step up. We never want to give up the easy bucket.”

Hernangomez smiled as he said Hornacek got on him “a couple of times” for not fouling.

“I’m still learning,” he said. “Actually I feel happy with me personally this season. Every loss you learn something. I try to use everything for next season, try to be more ready from the beginning, and I hope things change.”

Hernangomez and Porzingis have a close relationship. They played together in Spain for a season two years ago, and spoke at least once a week last year. Now that they’ve been reunited, they analyze each other’s game during film sessions together.

“I’ll be a critic of him always because I want him to be better,” Porzingis said. “We’ll watch film, we’ll talk about the game, what he can do better, what I can do better and we’ll learn.

“He was able to transition real easy in the locker room and on the floor. I’m happy that he’s out there with me on the floor playing 30-plus minutes.”

That’s likely to continue due to Noah’s situation.

advertisement | advertise on newsday

He’s missed 27 games with injuries, and will be suspended for at least 11 games to start next season, likely more. The suspension begins when Noah, who had knee surgery last month, is medically cleared to play.

“I think it’s bad news for us,” Hernangomez said. “He’s a great teammate. He teach me a lot this year. He had an injury. I tried to use this chance to play. I play hard. Next year I feel more ready than the beginning of this year, for sure. I’ll keep working the same way, try to help the team and we’ll see what happens with Jo and us next year.”