Theres a coding problem i have been thinking for couple of years perhaps every now and then, but have never really figured a good solution to it, so I decided to loan fellow CDN brains on this one.
C = Pacman
U = Ghost
. = empty space in screen
pacman chasing a ghost for example:
Noprmally it goes:
.....CCU... A Collision! (which you figure out through collision check)
however, there are many different kind of instances, when it happens to be that one or other of the collision characters is so fast that it might transport past the enemy that you should figure out if it hit or not through collision check.
Lets for example take a bullet.
P = Player
E = Enemy
- = Bullet
. = empty space
P.....E.-.. (Enemy was supposed to get hit, but since you are using collision check to check for hits, bullet just went past the enemy and collision check returns false)
For, i guess, years, i have been trying to figure out good solution for checking this thing out, but have never figure out one.
Bullet would be one easy example of this, since bullet would go on straight line and you would have pretty good idea whom it can even hit.
But lets take for example my latest speedgame. In this one you were using Mouse to hit enemies, this resulted, that not only you had to move your mouse fast enough, you also had to move it accurate enough. For when you tried to hit one of the enemies, you were quite likely to move your mouse fast enough that the pointer moved past the enemy already. And since program was checking simple collision check based upon mouse pointers current position, this resulted in false being reported, when in fact, enemy should have been hit.
But this is also good example case. Bullet might always move straight to right for example, but in mouse movement case, it could have moved at any place to any direction.
This can result in several problems.
For example, one possibility would be to trace the most direct route from previous x and y to new x and y, and then for example every 20 pixles do a collision check with everything to see if it hits something, but in pracitce enemies and mouse pointers form might be such, that they would be mising some points.
As example,i had round bocing glove in my speedgame.
lets say movement is following:
Okay, now lets suppose the object is rectangle like in my speedgae, and now lets take a look at one possibility of doing collision checks before reaching the final destination:
As you can see, in this example idea is ha box is 3x3 size, and then you get check with little jump forward. But this results in some obvious blind spots where some areas might have only 1 pixel sized checking point, when it should be checking for 3.
And especially, if other object happens to be moving the same way, then this can be a very big problem already, as they might be obviously colliding to each other, but due to program, both are checking only 1 pixel sized area from each other, which dont happen to collide.
Of course this can be get around by checking through every pixel of movement, but then that is not a good solution either.
Anyone have any good solutions for this problem?