I had to pause the dev of this game for some webdesigning on a project which isn't mine, i already had a ridiculous amount of work to match the deadline so that's even worse now. But well, that was already too big from the beginning so i guess removing a few more features is not that painful.Is making a car going backward a feature ?Day 11,12,13
: DOT PRODUCT !!!!!!!!!!!!!!!!
These three days were mainly about looking for the right collision algorithm and implementing it. As you can see on the screenshots in the previous posts my obstacles are actually not plain shapes but just some segments, a lot of tiny segments.
So here is the problem :
Since i'm just using a basic collision system, meaning "if car overlap segment then..." if my car is moving too fast, the steps start to be too big for my car to actually overlap that segment, it jump over like if there was nothing (B).
So i'm keeping each position as an (oldx,oldy) variable in order to build a segment between (x,y) and (oldx,oldy). Then i just have to check if there's a collision between the two segments, the one from the obstacle and the one from my car.
I dumped my shining three-level collision algorithm for a new one.
I found one and spent too much time implementing it, i almost pasted it. It ended up not working and after a lot of debugging i decided to give up and try another simple-that-i-can-understand-algorithm.
There's one called "the sweep line
. I didn't feel that one much.
Another one is called SAT
, Separating Axis Theorem and after googling a lot i want to point you that awesome tutorial
if you don't know it, resource2
That's pretty simple, you project each edge of your polygon on every axis (actually normals) and if each of your projections overlap, then there's a collision.
I only have some segments so that was even easier to implement.
Normal in red, projected points as white squares.Day 14 :
d-1 almost the beginning
I actually work with 3 files, my game, a simple version of it with a static list of points and an even rawer version, for debugging purposes. Part of this day was to move the update upwards, from file3 to file1 with all the stupid bugs in the way.
How rewarding it was when i saw the stuff work as expected (file2) and how depressed i was a few minutes later when i saw it in the actual game (file1). My car still moved through the walls sometimes, a lot less than before but the game just can't be played that way.
I think i would have given up if i hadn't found the solution in the next hour :
The car starts at red circle, in direction of red vector and collides with the wall. A collision response is made : blue vector. It says, go to that arrow position, assuming that since it's a collision response that's valid but in that case it isn't, the car is behind the obstacle.
That's actually hard to spot those kind of events since i'm having some really really small segments.
So i'm making two collision detections : a first one when my car just collides an obstacle and another one with the position of the collision response from detection1 and saying that if my car is colliding again (on second collision detection) go back to the position before everything happened. That's not really elegant but it works.Todo :
- Game mechanics ?
- Finish that collision stuff, there's some rare cases where the car still go through obstacles, those cases are, i think, not dependant of my programming but i have a simple idea to fix it.
- Stop using "since" in every sentence.
I guess you have all heard of the algorithms i'm talking about. My intention is not to teach anything to anyone, i'm actually new at game programming and i'm just doing it for the sake of the devlog.
Ok so at this time of the post i have 23 hours left until the deadline, LOCAL TIME. I don't even know how time i officially have. So 23 hours without sleeping and i'm going in my bed right now which means 14 hours.Just self-motivating.