Rolling Road with Physics

I’m trying to build a side-scrolling rolling road copter style game, think JetPack Joyride.

I have it working where the character stays still, and the obstacles spawn off the screen to the right and move across the screen as if the character was actually running. I assume this is best practice and is how I would have done it in other engines.

I want the character to have rigidbody physics and fall when it is hit by the obstacles, but the obstacles should not be affected by the collision.

Is the correct way to achieve this to just have box colliders on the obstacles and move their transform.position.x each frame?


I believe that it is actually best practice to move the character and camera in Unity. Else you can’t really use the physics engine (easily). How I would do it:

Assets → Import Package → Character Controller. Import.

Add “Character Motor” and “Platform Input Controller”-scripts to your character. Edit the “Platform Input Controller”-script to fit your game axis, and probably disable rotation or just write your own input script for the Character Motor.

Assets → Import Package → Scripts. Import.

Add “Smooth Follow” to your camera and have it follow your character or a child object to the character that is correctly rotated.

To make my character fall I would probably use an animation when he hits something and lock the input while he gets back up.