Welcome, Guest. Please login or register.

Login with username, password and session length

 
Advanced search

1411508 Posts in 69374 Topics- by 58429 Members - Latest Member: Alternalo

April 26, 2024, 08:57:44 AM

Need hosting? Check out Digital Ocean
(more details in this thread)
TIGSource ForumsCommunityJams & EventsCompetitionsVersus (Moderator: Melly)Two cars, one table (0.3)
Pages: [1]
Print
Author Topic: Two cars, one table (0.3)  (Read 5187 times)
caribou
Level 0
**



View Profile WWW
« on: February 07, 2011, 02:36:05 PM »


(non-projected version)

Player 1 :
UP = UPARROW
LEFT = LEFTARROW
RIGHT = RIGHTARROW
DOWN = DOWNARROW
FIRE = P

Player 2 :
UP = T
LEFT = F
RIGHT = H
DOWN = G
FIRE = W

PAUSE = DEBUG > collision lines + fps
+ / - = Scale the cars, physics is not scaled

You can use your own map 640*480 / PNG

Download 0.3

------
Hello,

I didn't intend to participate to this jam since i'm on another project but i stumbled upon

.

I find this idea awesome, so i started to play with some libraries a few days ago to see if that was doable in python and finally i'm having a "working" rough version of it playing on a static image, I have to make some serious tests with my webcam tomorrow with some proper lightings.

I'll put some screenshots tomorrow.

The versus part will be a kind of mariokart battle. As you may have noticed, the gameplay is not going to be original but the fun part for me is coding it and having cars moving around my table. Durr...?
« Last Edit: March 05, 2011, 02:39:29 AM by caramoun » Logged

LiquidAsh
Level 2
**



View Profile WWW
« Reply #1 on: February 07, 2011, 03:01:41 PM »

That video is awesome.  I already have a projector hanging from my ceiling, so I'll definietely have to play around with some similar concepts after the versus competition.
Logged
sepharoth
Level 0
**



View Profile
« Reply #2 on: February 07, 2011, 07:11:33 PM »

Hello,

I didn't intend to participate to this jam since i'm on another project but i stumbled upon

.

I find this idea awesome, so i started to play with some libraries a few days ago to see if that was doable in python and finally i'm having a "working" rough version of it playing on a static image, I have to make some serious tests with my webcam tomorrow with some proper lightings.

I'll put some screenshots tomorrow.

The versus part will be a kind of mariokart battle. As you may have noticed, the gameplay is not going to be original but the fun part for me is coding it and having cars moving around my table. Durr...?
"screenshots"  Big Laff
If you actually get this working, I will instantly worship you as god tier.
Logged

tzachs
Level 1
*


Look normal...


View Profile WWW
« Reply #3 on: February 08, 2011, 04:43:04 AM »

That video was beyond awesome!

I'm thinking that instead of racing, this technology can also make for an awesome multiplayer platformer, where the characters can jump on the objects and shoot down on the other characters, etc..
Logged

caribou
Level 0
**



View Profile WWW
« Reply #4 on: February 08, 2011, 04:15:40 PM »

Day 1 : Exploring

The first day was mostly looking at tutorials and documentation about OpenCV, the library i'm using. It contains a lot of algorithms to process images/videos.


Day 2 : Digging

I found that i needed to use the Canny algorithm, here what i finally got on a static image :



It looked ok at this time so the next step was to make a collision detection algorithm, i actually just looked for some point to square collisions.


Day 3 : Fun



I finally put a car (not my sprite) and some physics. As you can see, the car corners were at the original image position, driving between the pen and the lighter was tricky. So i fixed that corner thing and improved the smoothing collision algorithm.


Day 4 : Facepalm

Time to use the webcam. At first i was really enthusiast : I drew a track on some paper.



I got into some issues, since i had to scale down my car, the collision detection became really inaccurate because my -small- car went through these points, things which didn't happened before.

And i'm not even talking about the bottom left corner of this picture, i guess my excuse is that it was too blurry for a nice recognition but still there were too many spots like that so i thought about considering those points as segments.

I made a representation of it.



It's stupid of course i was just iterating through a simple list of points, i couldn't make a collision detection with these long segments between the shapes then. I spent some time looking for another algorithm until i noticed that i should have rtfm better. OpenCV actually returns a sequence instance, from which you can use those nice methods h_next() and v_next() : h_next() jump to the next list of points on the same level and v_next() to the next level, the inner shape for example.



I'm quite happy with the result (even with this ugly bottom left corner).

I just finished the rectangle to segment collision algorithm i'm now working on smoothing things a bit and handling collisions car behaviours.


Now the facepalm part.

Two things Facepalm :
- The screen i put on my video projector has an electronic piece missing.
- I didn't notice one important thing since i don't work with a projector, the projected image will contain the car which is going to be captured by the webcam and detected as collision points preventing the car from moving.

Those are the ideas i went for :
  • Knowing my car position i could ignore all the points around it. What a wonderful idea ! If the car goes into a wall it will actually ignore the wall as well and the car will go through.
  • There are some algorithms to detect images from a known source, i could give it the sprite image and then ignore what OpenCV is detecting as a car. Still, i'm afraid it will be too slow and that it will behave as above.
  • I can also detect what's moving, if that's not too greedy.

I'd love to contact the guy from the video to know how he handled this thing.

I don't have a projector right now so it's going to be hard to debug, i'm looking on internet for an order of that missing piece hoping that the delays won't be too long.

I still have time to make some researches about it but if it's getting too hard / too long i will stick on a non projected version for this competition, maybe with a kind of paint as a map editor.

But the projector version will still be my main goal, i can't stop fantasizing on those kind of tables.



Kiss
« Last Edit: February 08, 2011, 04:21:02 PM by caramoun » Logged

caribou
Level 0
**



View Profile WWW
« Reply #5 on: February 14, 2011, 09:58:17 AM »

Day 5 & 6 : Another one

I've added another collision detection layer on top of the previous one.



When there's a collision between the bounding boxes the 2nd collision detection algorithm is called which is basically about testing if the car is below or above the line, if not there's a collision.


DAY 7 & 8 : Looking for a nice collision response.

I didn't expect this part to be that painful, here is what i wanted to do:



I needed this green line. I was making line equations and atan stuff until i found that there were too many steps/greedy functions in that approach.


Day 9 & 10 : R = V + 2N((-V).N)

Vectors of course Facepalm and especially this formula :

R = V + 2N((-V).N)

R is that green vector, finally.
V is the car vector.
N is the normal vector to the wall (also) red line.

I found it via this pdf.


It's not enough. Even if i've got all the datas to make an accurate collision response (and i don't need that) I still have to make it smooth. What i did is saving my car position before looking for a collision, if a collision happens i apply the response vector to that old car position which makes the car pop back.

Actually i could apply a smoothing algorithm, that would be fine but i'm having an issue : my car goes through the walls sometimes, i guess that it's a basic problem where the moving object make some too big steps and therefore didn't really notice the object between the two positions.

I'm gonna check for an intersection between the actual position of my car and the old position. I shouldn't be able to drive through walls anymore and i could use that intersection point as a start for the response vector, making the thing a lot smoother.
« Last Edit: February 16, 2011, 09:52:52 AM by caramoun » Logged

X3N
Level 6
*


View Profile
« Reply #6 on: February 16, 2011, 09:24:18 AM »

Enjoying the dev log.
Related: the game where you draw hills on a planet and an astronaut collects them (Link anyone?)
Logged

destiny is truth pre-op
mikewest
Level 0
***


View Profile WWW
« Reply #7 on: February 16, 2011, 10:38:02 AM »

This looks seriously fantastic in concept.  I wish you the best with the snags along the lines of implementation.  Also, seconded to the great devlog comment.  Cheers.


Logged
charlestheoaf
Level 0
***


View Profile WWW
« Reply #8 on: February 16, 2011, 11:20:43 AM »

This looks pretty cool! The next time I go to visit the distant relatives with a projector, I'll take my computer a this game with me  Hand Thumbs Up Right
Logged

Animal Phase (twitter) | Local TIGSource: Crevice Climbers | Past: Puny Human
caribou
Level 0
**



View Profile WWW
« Reply #9 on: February 18, 2011, 03:05:51 PM »

Thanks for the encouragements ! And especially at this time of the dev since i'm having boring issues with divisions by zero and floating numbers. Beg

I'm on fixing these problems right now hoping it will be fine for monday, after that i'll dive into the game mechanics. If i'm on time this game will be very, very basic.

Next devlog sunday, i hope.
Logged

caribou
Level 0
**



View Profile WWW
« Reply #10 on: February 26, 2011, 04:18:27 PM »

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" Well, hello there! resource1, resource2. 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 ? (rockets)
- 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.
Logged

sepharoth
Level 0
**



View Profile
« Reply #11 on: February 26, 2011, 05:07:34 PM »

If you're going non-projector, I think it would still be cool to be able to give the game some random image off my hard drive to play as a map.
Logged

caribou
Level 0
**



View Profile WWW
« Reply #12 on: February 27, 2011, 06:20:10 AM »

Ok I'll try to do that. Ninja

I read more and more posts saying that they aren't going to meet the deadline.


Logged

caribou
Level 0
**



View Profile WWW
« Reply #13 on: February 28, 2011, 01:28:24 AM »

Phew i've never coded that much in a row, almost 24 hours. Durr...?

I wanted to meet the deadline so i skipped my night but i didn't expect to have a problem when making an *.exe, just at the end ! I just asked for help on stack overflow we'll see... So you'll have the half version of my game meaning only using a static picture.

There's still some collision bugs, the collision response really sucks so don't try to slide on the walls much. I'll describe the thing later now i'm going to bed.

I'm not adding my game to the finished projects thread since it's buggy, if tomorrow is still ok, maybe i'll add it.



Player 1 :
UP = UPARROW
LEFT = LEFTARROW
RIGHT = RIGHTARROW
DOWN = DOWNARROW
FIRE = P

Player 2 :
UP = T
LEFT = F
RIGHT = H
DOWN = G
FIRE = W

PAUSE = DEBUG > collision lines + fps

You can use your own map 640*480 / PNG
If the game is too slow it's certainly because that's badly coded but you can also try some simpler shapes. If you're using a really detailed image your fps will drop really quickly.

WEBCAM MODE is crashing right now.

2 Cars, 1 Table 0.1 (zip)
Logged

caribou
Level 0
**



View Profile WWW
« Reply #14 on: March 01, 2011, 03:45:59 AM »

Ok i guess i won't add my game, i don't know how to fix the issue i'm having when exporting. :<

I'll try to add sounds for the next release though.
Logged

caribou
Level 0
**



View Profile WWW
« Reply #15 on: March 01, 2011, 04:45:31 PM »

Ok no sound actually... Does anyone have some idle-engine-sound-loop ?

...But i finally managed to ship my game correctly, the webcam is now working !

I've found a bug with the collision response (again) this will be for the next release.

Download Two cars, one table 0.2
Logged

caribou
Level 0
**



View Profile WWW
« Reply #16 on: March 02, 2011, 07:21:58 AM »

0.2 is actually the same as 0.1...

The thing is that if you're playing with webcam enabled and quit the game, it will actually stay in your processes because I was not releasing the webcam capture. I fixed it in this version.

Download 0.2.1
Logged

caribou
Level 0
**



View Profile WWW
0.3
« Reply #17 on: March 05, 2011, 02:38:33 AM »

Ok, i lost motivation so here is the "last" update.

- FIXED an error when you're quitting the game while in the menu
- FIXED a big bug in the collision response
- you can drive backward faster

Download 0.3

Actually the real last thing i should add is a race mode, right now the battle mode is totally boring.


I learned a lot from this jam,

- Dead lines are great for motivation : i think i've made almost half of the game during the last 24 hours. The problem is that it's very hard to simulate this kind of pressure when there's no jam around :S

- Premature optimization blablabla : related to above, and even if every programmer knows that thing i actually really experienced it in this jam, my code is ugly but at least i didn't spent hours on a stupid menu or trying to find the best way to implement an algorithm...

- Vectors and the maths around it : i don't like to make some technical stuff much but when you do math with a game in mind it's almost fun. Also when performances are needed use vectors instead of trigonometry. An interesting article about the fastest way to find a distance between two points.
Logged

Pages: [1]
Print
Jump to:  

Theme orange-lt created by panic