- Home /
Best way to set up a custom controllable camera with movement around multiple axis?
Hi, I'm trying to set up a player controlled camera in a very specific way but I'm struggling to get the behaviour I'm after.
My game is 3d and set in a cylindrical tunnel, the player must rotate around this tunnel in order to perform platforming puzzles. The tunnel endlessly generates and moves past the player at speed while they stay fixed at 0, 0, 0 (think of something like Outrun or Super Hang-On, where the track moves to give the illusion of forward motion).
What I would like is for the camera to freely rotate around the Z-axis with an offset from the centre of the tunnel, while also being able to move 'up' in it's local Y-axis for jumps and vertical movement within the game-world. Something like this...
As well as this the camera needs to collide with various objects inside the tunnel such as ramps, raised platforms, obstacles, etc. Ideally it will collide with the tunnel too. If the player falls outside the tunnel they 'fail' and have to restart.
My current setup uses a camera, a rigidbody, a sphere collider and a configurable joint. With it I have the camera rotating around the Z-axis freely by applying a force to the camera when horizontal input is received, however as soon as I try to add the Y-axis movement things start to go wrong. The camera collides with the moving obstacle but often pings off and if it doesn't ping off it has very jerky movement and locks the Z-axis rotation.
I think it may be possible to use two joints, one for the Z-axis and one for the Y-axis, but when I start locking axis on one it negatively affects the other. I'm not convinced that this will solve the jerkiness either.
Does anyone know of the best way to approach this? Am I heading down the right path or should I find an alternative?
Thanks in advance.