Playing a 2D game in a 3D space.

Hi there, new poster here working on an unusual problem for a little indie project some friends and I are working on.

We’re trying to make a simple “helicopter tunnel” game (It’s about using your fingertip to dodge clouds and airplanes…as if on a long train ride/car trip), using a 3D play space and 2D game play. We’ve got a window facade, a back drop and some trick camera effects to get things to move by the window but we’re suffering on our game play. Here’s the problem:

We have the perspective camera set up at an angle to the actual game area, and we’re using a 3D Pointer script to constrain a pointer to the 2D plane the game objects will move along. The problem is that the ray from the pointer isn’t shooting straight into the background, it’s shooting off at a strange angle.

What we need: A way to have a canted perspective camera, pointer constrained to a 2D plane, and the ability to detect objects in the 3D space with that pointer.

Has anyone tried this before? Playing a 2D game in a 3D space?

I don’t fully understand the question, but I’m going to venture a guess that raycasting is what you’re looking for. You can build a ray corresponding to point in screen space using Camera.ScreenPointToRay(), and then use that ray in whatever way you want (for example, you could intersect it with the plane in which the game takes place in order to determine the game-space point corresponding to the screen-space position of the pointer).

Thanks for your reply!

The raycasting idea is what we are trying right now. But the question is how do we “bend” the angle that we draw from? We want to operate a game that behaves as if it was orthographic, from a perspective other than head on. The camera we’re drawing the ray from is at an angle to the plane we’re constraining the 3D pointer to, and it’s confusing things.

We will probably figure out a fix/stick with orthographic in the end, and this was a bit of a long shot asking for help as its a really hard question to convey, but thanks for responding!

Not sure if I’m understanding the problem correctly, but you could try casting against only the plane and getting back the UV coordinates of the hit. You should be able to map these coordinates to whatever game coordinates you are using.

Raycast from the screen to the plane.

Use those coordinates to raycast from the plane using the direction the plane is facing, should get the “bend” your after.

check out the 2d tutorial…

Even though I don’t fully understand what you’re trying to do, whatever it is, I’d be very surprised if it weren’t possible. In any case, I wouldn’t jump to the conclusion that you need to abandon your current approach.

If you’re not getting the answers you’re looking for, posting some diagrams or screenshots showing exactly what you’re trying to do might help.

Based on my understanding so far though, it sounds like all you need is a ray derived from a position in screen space, the intersection point of the ray with a plane, and a transformation of that point into the local space in which the game takes place. If that isn’t the solution you’re looking for, then again, I think a more detailed description of the problem will probably be needed.