I've got this part of my code working just fine. It jumps, slides along walls, fire bullets, the works.
void WL_GAME::DO_PLAYER_CONTROLS()
{
temp_obj=player->getobj();
// save all the temporary positions and angles
player->savevalues();
player->getcoords(&tempx, &tempy, &tempz);
player->getrotate(&temprx,&tempry,&temprz);
tempry+=mx;
dbYRotateObject(temp_obj,tempry);
/*SC_UpdateObject(temp_obj);
if (SC_GroupCollision(temp_obj,1))
tempry-=mx;*/
// Move forward/backward
if (dbKeyState(17) && player_move_speed<8) // KEY 'W'
player_move_speed+=1;
if (dbKeyState(31) && player_move_speed>-6) // KEY 'S'
player_move_speed-=1;
if (player_move_speed>=0.5)
player_move_speed-=0.5;
else if (player_move_speed<=-0.5)
player_move_speed+=0.5;
// Adding Strafe controls
if (dbKeyState(30) && player_strafe_speed>-8) // KEY 'A'
player_strafe_speed-=1;
if (dbKeyState(32) && player_strafe_speed<8) // KEY 'D'
player_strafe_speed+=1;
if (player_strafe_speed>=0.5)
player_strafe_speed-=0.5;
else if (player_strafe_speed<=-0.5)
player_strafe_speed+=0.5;
// do normal gravity falling if not jumping
if (!player_jump)
{
if (!SC_SphereCastGroup(1,tempx,tempy,tempz,tempx,tempy-2,tempz,30,0))
{
tempy-=2;
dbPositionObject(temp_obj,tempx,tempy-2,tempz);
}
}
// conrtol players jumping instead
else
{
if (SC_SphereCastGroup(1,tempx,tempy,tempz,tempx,tempy+player_jump_speed,tempz,30,0))
{
// if jump vector > 0 then we've hit something above
if (player_jump_speed>0)
player_jump_speed=0;
else
// hit the ground instead so stop jumping
player_jump=false;
}
else
{
// not collided so continue running the jump cycle
tempy+=player_jump_speed;
dbPositionObject(temp_obj,tempx,tempy,tempz);
if (player_jump_speed>-5)
player_jump_speed-=0.15;
}
}
// if not jumping and space pressed then start jumping
if (dbKeyState(0x39) && !player_jump)
{
player_jump=true;
player_jump_speed=5;
}
// move left/right
dbYRotateObject(temp_obj,tempry+90);
dbMoveObject(temp_obj,player_strafe_speed);
dbYRotateObject(temp_obj,tempry);
// move forward/backward
dbMoveObject(temp_obj,player_move_speed);
// Get new coords of New position
player->savevalues();
player->getcoords(&temprx,&tempry,&temprz);
// Now do sliding collision on player
coll=SC_SphereSlideGroup(1,tempx,tempy,tempz,temprx,tempry,temprz,30,0);
// reposition object using slide values if collided
if (coll)
{
dbPositionObject(temp_obj,SC_GetCollisionSlideX(),SC_GetCollisionSlideY(),SC_GetCollisionSlideZ());
}
// *** Control players firing
if (mc==1 && player_fire_count==0)
{
ADD_PLAYER_BULLET();
player_fire_count=20;
}
DO_PLAYER_BULLETS();
if (player_fire_count>0)
player_fire_count--;
SC_UpdateObject(player->getobj());
}
But, I need to add in it a part were it will handle slopes on the ground. I've read the tutorials in sparkys collision but I'm at a loss about the slopes. I'd like to add the ability to slide up and down down but not over a certain angle.
I know it's something to do with the SC_CollisionNormal commands. Once I've sussed that out I'm going to work on climbing stairs and then moving platforms.
Warning! May contain Nuts!