Hey guys, i wondering if anyone knew how to move an object only using velocites. I've about 90% of the code done, so far i got walking forward, walking backwards,walking left,walking right... the one thing i can seem to figure out is strafing. The object can only move forward,backward,left,right and cant strafe.
Here is my code, ill explain it below:
if(dbKeyState(17) == 1)
{
//dbMoveObject(2,5);
float posx;
float posy;
float posz;
float accx;
float accz;
float oldposx;
float oldposz;
posx = dbObjectPositionX(2);
posy = dbObjectPositionY(2);
posz = dbObjectPositionZ(2);
dbMoveObject(2,5);
oldposx = dbObjectPositionX(2);
oldposz = dbObjectPositionZ(2);
accx = oldposx - posx;
accz = oldposz - posz;
ODE_SetObjectLinearVelocity(2,accx*10,0,accz*10);
//ODE_SetObjectPosition(2,posx,posy,posz);
//ODE_SetObjectLinearVelocty(2,35,0,0);
dbText(0,26,dbStr(accx));
}
else
{
ODE_SetObjectLinearVelocity(2,0,-9.81f,0);
}
if(dbKeyState(31) == 1)
{
//dbMoveObject(2,-5);
float posx;
float posy;
float posz;
float accx;
float accz;
float oldposx;
float oldposz;
posx = dbObjectPositionX(2);
posy = dbObjectPositionY(2);
posz = dbObjectPositionZ(2);
dbMoveObject(2,-5);
oldposx = dbObjectPositionX(2);
oldposz = dbObjectPositionZ(2);
accx = oldposx - posx;
accz = oldposz - posz;
ODE_SetObjectLinearVelocity(2,accx*10,0,accz*10);
}
if(dbKeyState(30) == 1)
{
float posx;
float posy;
float posz;
float accx;
float accz;
float oldposx;
float oldposz;
posx = dbObjectPositionX(2);
posy = dbObjectPositionY(2);
posz = dbObjectPositionZ(2);
dbMoveObjectLeft(2,5);
oldposx = dbObjectPositionX(2);
oldposz = dbObjectPositionZ(2);
accx = oldposx - posx;
accz = oldposz - posz;
ODE_SetObjectLinearVelocity(2,accx*10,0,accz*10);
}
if(dbKeyState(32) == 1)
{
float posx;
float posy;
float posz;
float accx;
float accz;
float oldposx;
float oldposz;
posx = dbObjectPositionX(2);
posy = dbObjectPositionY(2);
posz = dbObjectPositionZ(2);
dbMoveObjectRight(2,5);
oldposx = dbObjectPositionX(2);
oldposz = dbObjectPositionZ(2);
accx = oldposx - posx;
accz = oldposz - posz;
ODE_SetObjectLinearVelocity(2,accx*10,0,accz*10);
}
}
Alright so basically what i am doing, is using the gdks built in move object commands. First i get their position, then move the object, then get their positions again. After that i find their velocities by subtracting the two. After that i set the objects acceleration using the setobjectlinearvelocity function. Basically everything should be working fine but strafing isnt. Does anyone know what im doing wrong?
Thanks in advance!