HI Guys,
I'm in dire need of help here, if spent ages trying to find where the problem is.. Basically i have some movement and jumping code that only works for a few seconds after moving.. If you execute the code and press the left and right buttons it will move on the correct angle, but after pressing either down or up AND then the left or right button the correct turn angles will get wrecked and it wont turn properly..
Heres my code, which can be tested straight away since i used cubes:
#include "DarkGDK.h"
void DarkGDK ( void )
{
float ya;
float ac;
float dc;
float an;
float x;
float y;
float z;
float angle;
float distance;
float height;
float smooth;
float Vy=0.0f;
float Vx=0.0f;
float PosX=0.0f;
float PosY=0.0f;
float Gravity = 0.2f;
bool Ground=true;
int JumpLeft=1;
int SpacePressed=0;
char str[128]="";
dbAutoCamOff();
dbMakeObjectCube(1, 300);
dbMakeObjectCube(2, 100);
dbMakeObjectCube(3, 100);
dbMakeObjectCube(4, 100);
dbPositionObject(2, 200,0,0);
dbPositionObject(3, 500,0,0);
dbPositionObject(4, 800,0,0);
dbScaleObject(1,15,15,15);
dbSyncOn ( );
dbSyncRate ( 60 );
while ( LoopGDK ( ) )
{
if (dbUpKey()==1)
{
ac=ac+2;
}
if (dbDownKey()==1)
{
ac=ac-2;
}
if (dbLeftKey()==1)
{
ya=ya-2;
}
if (dbRightKey()==1)
{
ya=ya+2;
}
if(dbSpaceKey())
{
SpacePressed++; //Pressed Jump Key
}
else
{
SpacePressed=0; //Did not press Jump Key
}
if(PosY < 0.1f) //Player is touching ground, reset jumpstate
{
Ground=true;
JumpLeft=1;
Vy=0.0f;
}
else
{
Ground=false; //Player not touching ground
}
if(SpacePressed==1)//We only want to detect when the Jumpkey was pressed.
{
if(JumpLeft>0)
{
Vy=4;JumpLeft--; //add vertical force, and will no longer be on ground
Ground=false;
}
}
if(Ground==false)
{
Vy=Vy-Gravity;
}
PosY=PosY+Vy;//Make changes to Y position
dbPositionObject(1,PosX,PosY,0);//position player
dbRotateObject( 1, 0,ya,0 );
dbMoveObject(1, ac);
angle=dbObjectAngleY(1)+Vx;
x=dbObjectPositionX(1);
y=dbObjectPositionY(1);
z=dbObjectPositionZ(1);
distance=350.0;
height=200.0 ;
smooth=12.0;
dbSetCameraToFollow( x,y,z,angle,distance,height,smooth,0);
dbSync ( );
}
return;
}
basically i just want it to move correctly, any help would be greatly appreciated..