|
How to smooth graphics |
kikabo
Member #3,679
July 2003
|
I like to work in units of (current_refresh_rate)/common_refresh_rate so that if the user happened to get that refresh rate then dt would usually be 1 for each frame. This way if you choose speeds for some of you game elements of dt * 1 or dt * 2 etc then for some users those game elements will be moving in whole pixels per frame which is as smooth as you can hope for. (ed: assuming that you are vsync locked) |
Kauhiz
Member #4,798
July 2004
|
Quote: I like to work in units of (current_refresh_rate)/common_refresh_rate Yeah, me too (I think this is what OpenLayer does), but I was using seconds in my example for simplicity. --- |
Albin Engström
Member #8,110
December 2006
|
Kauhiz said:
Quote:
Albin Engström said: I'll give you one more example. Suppose you're running your logic at 100 loops/s. This will mean that the delay between loops is roughly 0.01 s. Now, when you do this with delta timing, you don't limit the logic. For clarity, let's say you're measuring delta time in seconds. If your logic runs 100 times per second, delta time would be 0.01 s. That means you multiply stuff by 0.01. Then, on another machine, your logic runs 1000 loops/s. Now, the delta time will obviously be 0.001 s. So now you multiply by 0.001. 0.01 * 100 == 0.001 * 1000. So it doesn't matter how fast the game is running, it'll look the same. so if a thousand bullets move aagainsta target at 1000pixels per second and the logic rate is at 100 they will move 10 pixels per loop? something tells me i'll meet this kind of problem often(and i'll have to write alot of code to fix it, i can think of a few situations that i could fix thought), so i don't want to try it out :S.. but i can think of some situations where using deltatime is the right thing to do. How do you get over by like this? I don't really understand the other posts.. Now that i think about it.. i use delta time for my logic loops Approved? |
Kauhiz
Member #4,798
July 2004
|
Quote: so if a thousand bullets move aagainsta target at 1000pixels per second and the logic rate is at 100 they will move 10 pixels per loop? The amount of the bullets has nothing to do with anything. Apart from that, yes, except why would your bullets move 1000 pixels a second!? There's absolutely no sense in doing that! --- |
OICW
Member #4,069
November 2003
|
There's a great possibility that they would phase through an oponent causing no harm - considering you would check only if they're inside him. [My website][CppReference][Pixelate][Allegators worldwide][Who's online] |
kikabo
Member #3,679
July 2003
|
It sounds like Richards method would work best for you, at that speed your bullets would get 1 logic loop every 4 pixels which isn't too bad if your enemies are large (in terms of pixels). ed. If your game resolution is low then that does sound a bit too fast for bullets. |
Albin Engström
Member #8,110
December 2006
|
Kauhiz said: The amount of the bullets has nothing to do with anything. Apart from that, yes, except why would your bullets move 1000 pixels a second!? There's absolutely no sense in doing that! Hehe .. well, i think it's necessary for bullets to be able to acheave such speeds, it's about feeling.. i don't like when you have this awesome machinegun and a million aliens moving thowards you, and you bullets move in slowmotion(with a booring sound effect)... it should be like BAM BAM BAM just spitting out a shit load of bullets at a really high speed slaughtering everything. . also, i like small targets :/(i like targets of all sizes too - -).. OICW said: There's a great possibility that they would phase through an oponent causing no harm - considering you would check only if they're inside him. yeah. and to me, that's a very big problem. kikabo said: It sounds like Richards method would work best for you, at that speed your bullets would get 1 logic loop every 4 pixels which isn't too bad if your enemies are large (in terms of pixels). ed. If your game resolution is low then that does sound a bit too fast for bullets. 4 pixel is to much . 2 pixels is to much.. bullets should be able to hit bullets - -. i'm fine with one pixel right now... but i might change my mind and go with 1/4 pixels. hehe, it would be approximately 1.56 screen widths per second... i guess thats enought . |
Richard Phipps
Member #1,632
November 2001
|
If your bullets are one pixel in size they are too small to be seen properly. The minimum should be 2 x 2 or probably 4 x 4. In that case they can move at 2 pixels per second or 4 pixels per second and still overlap to cause collisions. |
FuriousOrange
Member #7,305
June 2006
|
I had nothing to do this lunch break so i thought i'd make this picture. It explains why having a bullet move speed of 1000 px is a bad idea. Best to have big heavy alien smashing bullets travelling at 5 px per update than a stealth bullet thats too quick for its own good. Enjoy! {"name":"591251","src":"\/\/djungxnpq2nug.cloudfront.net\/image\/cache\/9\/8\/98d27599548301c3caf1d69166a63e68.jpg","w":846,"h":745,"tn":"\/\/djungxnpq2nug.cloudfront.net\/image\/cache\/9\/8\/98d27599548301c3caf1d69166a63e68"} |
Audric
Member #907
January 2001
|
Uhm... I may be missing something very obvious with delta-timing, but since you don't enforce a constant "time interval" between updates, don't you HAVE to take into account the fact that this interval can be between 0 ms and +infinity ? In particular, if something on your computer cause a big performance hit (something like: CD starting to spin, ctrl-alt-del, antivirus or other hungry program), there can easily be a second-long gap. I think, for delta-timing, you NEED to build a system that can handle such gaps. If you don't, the game will behave incoherently on slower computers, and randomly on yours. |
OICW
Member #4,069
November 2003
|
But that's what is delta time about. Since you can't be sure that the time between frames is the same, you aply delta time. You just meassure the time between two frames and multiply by it all movement done between theese two. Just like in real world. [My website][CppReference][Pixelate][Allegators worldwide][Who's online] |
Tobias Dammers
Member #2,604
August 2002
|
Audric has a point though. If you use delta time, and frame times can be anywhere between 0 and +inf, then you can't guarantee any maximum distance travelled per frame for any object. --- |
OICW
Member #4,069
November 2003
|
ad c) like checking whether there's something in the path of the bullet, or if there's possibily, that something will get in there considering the velocities. [My website][CppReference][Pixelate][Allegators worldwide][Who's online] |
Audric
Member #907
January 2001
|
See the attachment for an example: Fixed frequency does not solves such issues (it makes it easier to avoid them), but it has the advantage that the situations are fully replayable : just record the seed of your RNG, and the inputs of each frame. |
Kauhiz
Member #4,798
July 2004
|
Quote: well, i think it's necessary for bullets to be able to acheave such speeds, it's about feeling Again, having a 1px bullet moving at 1000px/s is just pointless. No one will be able to see that. If you want "realistic" (read fast) bullets, just check for collisions along the trajectory rather than against an actual projectile. There's no way this can get screwed up. --- |
OICW
Member #4,069
November 2003
|
Audric: first of all you just check whether the velocity vectors aren't colliding, or more specifically if the vectors from point of origin to point of destination (between the two frames) doesn't collide. If yes, then you have a collision. Just do it only for fast moving objects - like a bullet which will check other objects if they're in the way. After that you should analyze if there's such a point along the trajectory where the bullet was inside the object. [My website][CppReference][Pixelate][Allegators worldwide][Who's online] |
Paul whoknows
Member #5,081
September 2004
|
FuriousOrange, I really like your sketch! do you have more of them? ____ "The unlimited potential has been replaced by the concrete reality of what I programmed today." - Jordan Mechner. |
Audric
Member #907
January 2001
|
OICW, my point was not to detect if there was a collision, what collided with what... (and where in space and time) |
OICW
Member #4,069
November 2003
|
Well at first you must know if something collides. Ussually as a side effect you know what and where it collided. For instace, if you check those two vectors from my previous example whether they collide and the output will be yes, there will be also somewhere information where did they collided - it's in the nature of vector intersection checking. So if you know that the the vector a and b collides, you'll be also provided with [x][y][z] coordinates. Which is exactly what you're seeking for. [My website][CppReference][Pixelate][Allegators worldwide][Who's online] |
FuriousOrange
Member #7,305
June 2006
|
Paul whoknows, i'm sorry to say I don't! |
Tobias Dammers
Member #2,604
August 2002
|
OICW: It's a bit harder than that. For checking 2 moving objects against each other, you need to take their radii into account. The formula goes something like this: dist(dt) = hypot(x1 - x2 + (v1x - v2x) * dt, y1 - y2 + (v1y - v2y) * dt) - (r1+r2); and you have to solve the equation for dt where dist == 0; this will give you 0, 1 or 2 solutions. If there are no solutions, there is no collision. If there is one, then the objects hit each other only tangentially, and you can probably consider it a non-collision as well. If there are 2 solutions, then you need to use the smallest non-negative solution. If the solution is larger than your desired maximum dt, then you can ignore it. If both solutions are negative, there is not collision. If more than 2 objects are involved, you need to check each object pair, and start with the first collision you detect. Forward the simulation to that point, handle the collision, and run all checks against these two objects again. Keep doing this until dt has reached its desired maximum for that frame. --- |
Matthew Dalrymple
Member #7,922
October 2006
|
To FuriousOrange and his image: I'm sorry but I have to give props to FuriousOrange... I CANT STOP LAUGHING. It might just be me at 3:20 in the morning but yeah, I saw that and wow its great. Sorry to pull off the subject =-----===-----===-----= |
kikabo
Member #3,679
July 2003
|
I haven't read all of the replies since but it sounds like there is confusion between the stated 1000 pixel moves per second and pixel moves per update. 4 @ 250hz = 1000 per sec |
OICW
Member #4,069
November 2003
|
Tobias: well ok of course if you need to check huge objects you need to apply some radius (if it's enough). But maybe before some slower solutions for non-circle shapes (which is more common) it's good to check whether it's even possible for them to collide. [My website][CppReference][Pixelate][Allegators worldwide][Who's online] |
Audric
Member #907
January 2001
|
Still in delta-time, If you don't, it will be VERY visible that the shooting frequency is affected by system load : the distance between the projectiles will not be constant. |
|
|