Some time ago, I was making a side-view racing game, but came across a problem I couldn’t find a suitable solution to. However, I didn’t stop thinking about it and hate to leave it unfinished after putting so much work into it.
Previously, I had trouble explaining what I wanted to do, but will try again.
This is in a 2D side scroll, platform-style game with the physics engine. What I want to do is be able to smoothly “change lanes” or move closer/farther on the “platform”. Alas, using the physics engine on a 2D side view seems to make this difficult to implement. Currently, I have multiple tiles stacked upon each other to act as the different lanes of the road. Changing the Z order affects what tiles the vehicle is on. This has the problem that the vehicle “falls” onto lower tiles but worse is going up, where it erratically “jumps” up onto the higher tiles, since it is clipping through the bounding box.
I’ve included some images to help explain. The one I made has a 3D box and was wondering if I could use those in my 2D game. The top of it would act as the road surface tiles with the vehicle moving closer/farther along the top. Think of it as acting like the “Mode 7” on Super Nintendo. Of course, this depends on whether or not the 3D objects can work in my 2D game and with the physics engine.
I don’t think you need to create objects to lock the car into lanes. You can just increase the y position to move down and decrease it to go up. You can increase the scale of the object while going down if you want the car to get bigger to seem like it is getting closer to the camera.
If you set the origin of your sprites to be on the bottom of the sprite, you can simply set the z-order to equal the y position every frame and cars closer to the bottom will also appear in front of cars with higher position which are behind.
Finally, you can change the “bounding box” of objects in the sprite editor. Instead of making the bounding box cover the whole sprite, make it cover just the area of the car at the bottom around the wheels and part way up the car. That gives the cars some thickness for collisions while still allowing them to pass behind each other in the space of the sprite that has no bounding box.
Well, its not the “locking” the cars into “lanes”, but the actual “visual movement” when “changing lanes” (Z-order) in the physics engine.
I previously tried to scale the size of vehicles but had the problem of the wheel joints not moving with the scaling. Though, now that I think of it again, I should take another look at it. Is there a way to smoothly move the joints so they follow the scaling? (I had them scale gradually as they “change lanes”.)
Well, I’m just going to use multiple tile method for now. Sure, it will complicate map making, but at least it works.
I tried removing and re-adding the wheel joints. Also tried offsetting the center point. Both had undesirable results. Mainly, the wheels would not properly attach, causing them to sometimes move away from the vehicle or not act correctly.
The lane-to-lane “jump” from the stacked tiles wasn’t quite severe as I had though.