I have blocks instead of lego pieces and also want a retro feel.
The blocks are snapped the the nearest int making collision simpler or so I thought.
The collision detection works perfect when the player collides with the side of a block, however the problem is diagonal blocks.
Working: [ ]--X[ ] [ ]Not Working:[ ] ---> [ ]/ /[ ]---- [ ]
My original source:
if (speed!=0) { float xNew=x-speed*(cos((zRot)*3.14/180)); float yNew=y+speed*(sin((zRot)*3.14/180)); vertex position[3]; position[0].x=xNew; position[0].y=yNew; position[0].z=z+.5; if (Map->checkCollision(position[0])==false) { xNew=x-speed*(cos((zRot)*3.14/180)); yNew=y+speed*(sin((zRot)*3.14/180)); x=xNew; y=yNew; } }
My next failed attempt:
if (speed!=0) { float xNew=x-speed*(cos((zRot+45)*3.14/180)); float yNew=y+speed*(sin((zRot+45)*3.14/180)); vertex position[3]; position[0].x=xNew; position[0].y=yNew; position[0].z=z+.5; xNew=x-speed*(cos((zRot-45)*3.14/180)); yNew=y+speed*(sin((zRot-45)*3.14/180)); position[1].x=xNew; position[1].y=yNew; position[1].z=z+1.5; if (Map->checkCollision(position[0])==false && Map->checkCollision(position[1])==false) { xNew=x-speed*(cos((zRot)*3.14/180)); yNew=y+speed*(sin((zRot)*3.14/180)); x=xNew; y=yNew; } }
Function used in above source:
bool chunk::checkCollision(vertex Point){ for(int a=0;a<position;a++) { if ( grid[a].x <= Point.x && grid[a].x+1 >= Point.x && grid[a].y <= Point.y && grid[a].y+1 >= Point.y && grid[a].z <= Point.z && grid[a].z+1 >= Point.z ) { return true; } } return false;}
^ About Above ^
grid array, is an array that contains the x,y and z of the blocks in the game, where the max amount of blocks are 24576 block.
How this works is:
It figures out where the player will be next step
That point is then checked to see if it is inside a block.
If so then Speed = 0
else let the player move
Does anyone know how I can fix this and get more speed?
Thanks in advance