- Home /
Move 3D camera on 2D plane
Hi All,
I've got a tricky problem I'm trying to find an easy solution for.
I'm building a game where the player is going down a tunnel, vertically. The speed is constant, just moving down this tunnel at the same speed from start to finish. The way I've built this is the player is static in space (0,0,0) and the tunnel spawns in sections bellow him (0,-10,0) and moves to a point upwards (0,10,0) and then disappears. The tunnel infinitely spawns underneath him and moves up, to make it seem like he's moving down. Pretty standard.
Now, the problem I'm having is I want the player to be able to move to the edges of the tunnel, on the x/z axes. I've currently attached a rigidbody to my main camera, and a script with only:
transform.Translate(Vector3.forward * Time.deltaTime);
This almost does what I need, except I don't want the camera to actually move forward (in this case, down the tunnel on the y axis), just move along the x/z plane depending on where the user looks.
So I could of course just have a collider on the player, and an invisible floor with a collider, which does work, but it's nasty. I'm trying to find something clean and sensible: Constant 2D movement along the x/z axes in the direction the camera is looking.
Thanks in advance.
Hyper
A 2D plane by definition is a subset of 3D space where all values can be attained from two linearly independent 3D vectors. In the case you want just the X/Z components, you'll want to fix the Y value for your translations to to value you see fit.
For your translations, you would just replace that component manually.
Resetting the Y position every frame is indeed a good solution! I like it.