Hi guys,
Ok. I just want you guys to check whats the problem in the code.
When i collide with my terrain's{ter} verticle wall, it jitters up and down my camera(FPS). Is there any way to stop that but still need to collide with a wall perpendiculer and any thing of 0-70 degree must be passable(can jump over it like stairs).
P.S. Check the jump too if its realistic or not.
void controlcamera(int cam, float speed,float tu,int ter)
{
float ox,oy,oz,x,y,z,ax,ay,az,j=glo_plajump,g=glo_plagravity;
char text[200];
x=dbCameraPositionX(cam);
y=dbCameraPositionY(cam);
z=dbCameraPositionZ(cam);
ox=dbCameraPositionX(cam);
oy=dbCameraPositionY(cam);
oz=dbCameraPositionZ(cam);
bool zoom=false;
if (dbControlKey())
zoom=true;
dbSetCameraFOV(cam,90);
if (zoom==true)
{
dbSetCameraFOV(cam,15);
tu=tu*2;
}
ax=dbCameraAngleX(cam)+(dbMouseMoveY()/tu);
ay=dbCameraAngleY(cam)+(dbMouseMoveX()/tu);
if ( ax > 80 && ax <180 ) ax = 80;
if ( ax < 270 && ax > 180 ) ax = 270;
dbRotateCamera(cam,ax,ay,0);
if (dbKeyState(17)==1)
{
x=dbNewXValue(x,dbCameraAngleY(cam),speed);
z=dbNewZValue(z,dbCameraAngleY(cam),speed);
}
if (dbKeyState(30)==1)
{
dbYRotateCamera(cam,dbCameraAngleY(cam)-90);
x=dbNewXValue(x,dbCameraAngleY(cam),speed);
z=dbNewZValue(z,dbCameraAngleY(cam),speed);
dbYRotateCamera(cam,dbCameraAngleY(cam)+90);
}
if (dbKeyState(31)==1)
{
x=dbNewXValue(x,dbCameraAngleY(cam),-speed);
z=dbNewZValue(z,dbCameraAngleY(cam),-speed);
}
if (dbKeyState(32)==1)
{
dbYRotateCamera(cam,dbCameraAngleY(cam)+90);
x=dbNewXValue(x,dbCameraAngleY(cam),speed);
z=dbNewZValue(z,dbCameraAngleY(cam),speed);
dbYRotateCamera(cam,dbCameraAngleY(cam)-90);
}
if(SC_SphereCast(0,ox,oy,oz,x,y-13,z,3.5,0)>0)
{
if(dbSpaceKey()==1)
{
j=70;
g=0;
}
}
if(j>-90)
{
g=g+(dbSin(j)/3.5);
if(g>2)
g=2;
j=j-3;
}
else
g=-3;
glo_plagravity=g;
glo_plajump=j;
sprintf_s(text,200,"gravity=%f",g);
dbText(0,0,text);
y=y+g;
if(SC_SphereCast(ter,ox,oy,oz,x,y-13,z,3,0)>0)
{
ox=(SC_GetCollisionSlideX()-x)/1.5;
oz=(SC_GetCollisionSlideZ()-z)/1.5;
if(dbABS(SC_GetCollisionNormalY())==0.5)
{
oy=(SC_GetStaticCollisionY()-y)+13;
}
else
oy=(SC_GetCollisionSlideY()-y)+13;
x=x+ox;
y=y+oy;
z=z+oz;
}
if(y<-150)
y=140;
dbPositionCamera(cam,x,y,z);
}
ALLAH IS THE GREATEST
May he forgive me