BUENA PARK, Calif. — The Marine gripped his six-shooter, pointed it at the horizon and took a deep breath.

“Let’s do it,” he barked, kicking off a brief but furious gunbattle with a horde of robot cowboys, their eyes glowing red.

Derek Phelps, a leatherneck stationed at Marine Corps Base Camp Pendleton, was not only fighting off an invading robot horde but also his 8-year-old brother, Tyrus, who stood next to him, trying to kill off more invaders than his older brother.

“Ah, first place,” the Marine shouted after finishing the virtual reality game “VR Showdown in Ghost Town,” the newest attraction at Knott’s Berry Farm in Buena Park.

In the theme park industry, attractions that encourage head-to-head competition are growing in popularity because they entice visitors — particularly video game-loving millennials — to visit a park repeatedly to improve their score or to beat new challengers.

For regional parks such as Knott’s Berry Farm, attractions that add an interactive gaming element also help them compete against the big-dollar attractions at Disneyland and other destination resorts without breaking the bank.

In Southern California, Knott’s “VR Showdown” is among three gaming attractions that have launched recently or are scheduled to open this summer. They join two similar competition-based attractions that opened at local parks in the past two years.

Although games with a competitive element go back to the days of the old-fashioned carnival midway, theme parks became interested in keeping score as technology improved and the cost of virtual reality goggles and other components dropped.

In Knott’s “VR Showdown,” players wearing virtual reality goggles stand in an empty room. Overhead cameras monitor the players’ pistols to track their shots, and the wireless equipment allows players to move around the room. Competing players appear as avatars on the goggles’ screen. A score appears in the goggles at the end of the game.

“The whole notion of tapping into people’s competitive spirits is what motivates it,” said Monty Lunde, chief executive of Technifex, a Valencia company that designs, engineers and produces attractions, with a focus on special effects and interactive systems.

Such attractions aim to entice the burgeoning population of young gamers, and designers say the challenge is to create a superior experience to what the players might get on their home gaming setup.

Student Emiliano Perez of Fullerton played “VR Showdown” at Knott’s Berry Farm recently and said it outmatches the virtual soccer games he plays on his home Xbox system. “It’s like you are part of the game,” the 13-year-old said.

The virtual reality attraction at Knott’s even includes little-known strategies — or “cheats” — to boost a player’s score, said Christian Diekmann, corporate vice president for strategic growth at Cedar Fair Entertainment Co., which owns 13 theme parks and water parks, including Knott’s Berry Farm.

“We can deliver now the kind of attraction we couldn’t do 10 years ago,” he said.

Diekmann declined to disclose the price of the new ghost town addition but industry experts say such gaming attractions can be built for under $15 million.

In contrast, Universal Studios Hollywood spent an estimated $500 million last year to open its Wizarding World of Harry Potter section and Disneyland is spending an estimated $1 billion to build a Star Wars-inspired expansion, set to open in 2019.

Large theme park resort operators have opened a handful of gaming attractions in the past but are now putting most of their investments in big-dollar immersive attractions.

In 2005, Disneyland opened Buzz Lightyear Astro Blasters, which puts riders on a slow-moving vehicle and lets them shoot at targets, robots and aliens with a laser blaster. Three years later, Disney California Adventure opened Toy Story Midway Mania, another target-shooting attraction that adds a 3-D effect.

Disneyland resort spokeswoman Suzi Brown noted that the Shanghai Disneyland Resort opened last year with a Buzz Lightyear attraction that includes a gaming element. She would not rule out building similar attractions at local parks in the future.

“We will continue to invest in experiences that use cutting-edge technology to immerse guests into their favorite stories,” she said.

There are no interactive gaming rides at Universal Studios Hollywood, but in 2000, sister park Universal Studios Orlando opened Men in Black: Alien Attack, in which riders shoot at aliens to boost their score on a vehicle monitor.

Industry experts say big resort parks may not be interested in interactive gaming rides because they are targeting out-of-town vacationers who want to experience big-budget immersive rides, not attractions that remind them of a carnival game.