I’m making a game for the Traffic Jam (which I hope will come soon!) and I’m stuck on something.
My game allows you to switch lanes, using the up or down keys. But it’s really easy to crash into a car by 1 pixel, which can be very annoying. So, I’m in the process of implementing smooth lane changing, so it will change to the next lane and align perfectly, instead of having you to align it yourself, kinda like a really expensive car that lane changes for you.
For some reason, changing lanes down (right if you hold it at 270) is perfectly fine, while changing lanes up (left), it will not align to the road. I for the life of me cannot understand why my game is doing this to me and you are all smarter than me.
Here is the troubling game:
(All the controls should be explained in the start screen - if you don’t get it just ask!)
I’m going to write down the process of debugging and fixing with blurring.
It’s always:
to reproduce the bug in a simplified scenario;
locate the cause
fix
For step 1, read the code, find the code relevant and remove those not to make testing quick and easy. (I removed the slow cars, which interrupts testing(causing game over)
Step 2, locate the bug with logging, logging is the cheapest and easiest way for straightforward bugs. This time, its obvious that y of car is not correct updated after up is released, so I add some logs:
Also, as you mentioned, releasing down works fine, so we may want to compare them for a better understanding, that’s why logs are added to down releasing event.
The changes to y for up / down should not be the same, consider the following:
Let’s suppose the of y of car is now 28,
a.) for moving up, y should be set to ?
b.) for moving down, y should be set to ?
Thank you felixtsu!
I’m currently not at my computer, so I can’t run through the whole debugging thing.
Thank you again for the time and effort you out into helping me!
It’s so tempting just to unblur the hint ! Agh!
Got it to work! Thank you so much for helping me with my game!
BTW, you accidentally put the answer when you were showing me this photo:
It includes the 16 -
Thank you! Writing the text took forever
I got the idea from a mobile game that I really liked and decided to create the game in Traffic/Car theme so I could submit it to the Traffic Jam!