Hi all,
So guys please help me with this function. My space ship is moving in the direction its facing(inc by mouse x). And the problem is that the object is not moving in the right direction. That is its moving a little tilted. As far as i know that when the ay comes in 20 to 80 , the newxvalue and z value is not calculated correctly.
Note that some of the values are initialized in the object class. So ay is not changed at all except in this function.
The code function:
void updateplayer()
{
float x,y,z,nx,ny,nz;
dbPositionMouse(125,125);
char text[200];
x=dbObjectPositionX(obj);
y=dbObjectPositionY(obj);
z=dbObjectPositionZ(obj);
vx=vx+(0-vx)/weight;
vz=vz+(0-vz)/weight;
ay=dbWrapValue(ay+dbMouseMoveX()/4);
dbYRotateObject(obj,ay);
if(dbKeyState(17)==1)
{
vx=dbNewXValue(vx,ay,speed);
vz=dbNewZValue(vz,ay,speed);
}
if(dbKeyState(31)==1)
{
vx=dbNewXValue(vx,ay,-speed);
vz=dbNewZValue(vz,ay,-speed);
}
if(dbKeyState(30)==1)
{
ay=ay-90;
vx=dbNewXValue(vx,ay,speed);
vz=dbNewZValue(vz,ay,speed);
ay=ay+90;
}
if(dbKeyState(32)==1)
{
ay=ay+90;
vx=dbNewXValue(vx,ay,speed);
vz=dbNewZValue(vz,ay,speed);
ay=ay-90;
}
if(vx>2) vx=2;
if(vx<-2) vx=-2;
if(vz>2) vz=2;
if(vz<-2) vz=-2;
x=x+vx;
y=y+vy;
z=z+vz;
dbPositionObject(obj,x,y,z);
nx=dbNewXValue(x,ay,-35);
nz=dbNewZValue(z,ay,-35);
nx=dbCameraPositionX(obj)+(nx-dbCameraPositionX(obj))/1;
nz=dbCameraPositionZ(obj)+(nz-dbCameraPositionZ(obj))/1;
sprintf_s(text,200,"vx= %f",vx);
dbText(0,0,text);
sprintf_s(text,200,"vz= %f",vz);
dbText(0,10,text);
sprintf_s(text,200,"ay= %f",ay);
dbText(0,20,text);
dbPositionCamera(obj,nx,15,nz);
dbPointCamera(obj,x,y+15,z);
}
Thanks in advance.
Your signature has been erased by a mod