4 hours ago, Anri said:
The movement of an object, so long as it did not overshoot the dimensions of a grid-tile, could have been "pixel perfect" and still use a grid for collision detection, in the manner you describe.
Yes, so I have also programmed an algorithm that would achieve pixel perfect movement.
I use the tile map array to detect collision. The character you control has coordinates for that tile map and I check the next tile if it is marked as walkable or not. I use another tile map array with the same dimensions and that one holds boolean values. True means it's blocked, so not walkable, and False means it's walkable. I then use another set of variables for the same character that tracks it's offset in pixels from the tile map coordinates. The offset ranges from 0 to 15 because each tile is 16x16. When the character's offset are <0 or >15 the character's variables for the tile map are incremented by 1. I also have a variable for incrementing the offset variables by more than 1 (1 is a bit slow and would be comparable to walking in a game) so that the character can move faster, which is like running or sprinting I guess.
The camera or view area (how many tiles are displayed on screen) has it's own coordinates for which tiles should be displayed (start x, y and end x, y: which makes the view area). The display on screen of those are also offset by another set of variables for the camera and those variables follow the same rules as the character's offset variables.
The issue I'm having is I cannot seem to take into account the offset variables and tile map variables correctly so that the collision is detected properly between the character and a hard object on screen. My algorithm uses the tile map array to detect if the tile next to the character in the direction they are walking is walkable or not, if it's not, it will get the pixel coordinates of that tile and the pixel coordinates of the character and then check each pixel the character and the tile are comprised of until they overlap (I plan to also check the actual pixel value of the surface matching the textures of the character and object and consider a pixel only if it's different than the colorkey (255,0,255), that way I can have pixel perfect collision) at which point a collision would have occurred and the character's offset variables are not incremented. That works partially when I run and play the game. The character stops when it encounters the object but when the character is aligned in a certain way with the object it walks through it because, I assume, the tile map coordinates and the object are not aligned in a way that detects as collision.
At the moment the grid-based movement I have programmed works perfectly but pixel perfect looks smoother, lol.
Sorry if I'm bad at explaining this, I did not study how to make a game nor programming, but I have been playing games and programming for 22 years. So I can figure out a lot of things to make a game I would enjoy playing, and hopefully others too.
I would appreciate if anyone would know of a way to achieve pixel perfect movement or can point me towards a website. Also I'm using SDL2 and Free Pascal for my game. Too late to switch to another programming language, I have 19198 lines of code: character and npc menus and interactions, world/level creation, combat and so on. Been working on this for over a year.