# Pinball Problem: Curved Containment with Cannon?

A pinball game begins with the plunger launching the ball - it shoots up and curves over the top before gravity pulls it down into the playfield.

What is a simple way to add a curved wall to my pinball playfield using Cannon? Initially, I thought a half cylinder would be the answer but, unlike Three js, Cannon’s cylinder constructor doesn’t have options for thetaStart and thetaLength.

I imagine this could be done with a trimesh, but it seems like there would be a simpler solution?

Any insight would be appreciated.

I’d use trimeshes for sure.
This demo is full of trimeshes.

The large glass ball is a trimesh and acts as a container. It is created from an obj geometry.

There are also two rails which are trimeshes. One is spinning inside the sphere collecting balls as it turns over. The other is outside catching them as they come out.
The balls role along them as if they are real rails.
The result is a random series of numbers every time you refresh the browser and wait.

I was going to create a pinball machine once, but I got busy with other ideas.

Thank you! I’ll be checking out these resources over the weekend.

I recently purchased the Kindle version of your book, so your response is well-timed and appreciated.

And glad to hear that you have given thought to a browser-based pinball game. I’m thinking it could be an entertaining bit of immersive nostalgia when paired with XR and force feedback.

1 Like

This looks much better than I imagined I was going to build.
OUIGO - Let’s play

And this is a write up
How we built a pinball. Ouigo Let’s Play — Case study | by Merci-Michel ® | Medium

I will still make one probably some time. It won’t look as good as this though, but it should still work.

2 Likes

This is a fantastic resource. Thank you for sharing.

The article’s gameplay video - where the camera follows the ball around the playfield - illustrates the potential upside of using an XR device; real-world pinball differs from a video game in that the player is continuously moving their gaze over a physical playfield (like a spectator watching a tennis game) along with periodic glances at the scoreboard.

I like the idea of using XR in a limited way (standing in one spot while moving your head) to bring an old-school, analogue experience to life.

I’ve started building something now.
It’s not a pinball game, but it does have a ball in it.
And its VR. You follow the ball and control it.
The ground is made up of many CANNON trimeshes.

I’m testing it on Oculus Quest 2 using the inbuilt chrome browser.

Playable Demo : https://ball-vr.sbcode.net/

You roll around and find a spring.

and that then shoots you into near orbit.

1 Like

This looks very interesting. I’ll plug in my Oculus and check it out. Thank you.

Also, I’ve been making good progress using trimesh - thanks for pointing me in the right direction.

Unfortunately, attempting to view the link with my 2019 Oculus is resulting in a WEB XR NOT AVAILABLE message (using the default mozilla browser). The desktop version looks great, so I’m a bit disappointed.

I’ve been meaning to update my headset - any recommendations for contemporary Web XR-friendly devices?

Update on my ‘Pinball Problem’:

1. I made a trimesh-enabled function, ‘CannonCurve’, with props: {
height,
thetaStart,
thetaLength
}
It returns a curved wall (could also be a ramp, depending on its orientation relative to gravity).

2. Since Cannon Planes are infinite (and since the Box substitute felt a little hacky), I made a trimesh function, ‘CannonRect’, to create a single 2d rectangle. In addition to the playfield ‘floor’ (as seen in the screen cap), I plan to use CannonRect to create the straight bounding walls of the pinball playfield.

3. I’m using CannonDebugger to develop a playable wireframe (one of the reasons I wanted an alternative to Cannon Plane).

4. I’ve got an fps display (via ‘stats.js’) to keep track of performance while I’m developing.

Next Steps: I’m going to do some research into the mechanics of real-world pinball games (bumpers, flippers, etc) so that I can better emulate the feel of pinball’s kinetic, visceral vibe.

I would really appreciate ongoing advice/feedback (is there a difference?). I work best when I feel confident that I’m headed in the right direction.

1 Like

Ha! I just looked at the original post - I clearly need to read more carefully (I think I was overly excited to try out the link).