Hello again,
I should note, the dbMoveObject(...) function DOES move on all three axes.
This means if your object is tilted slightly up or down, as well as turned left or right, it will be moved up or down the Y-axis as well as along the x and z axes.
There are a few ways to overcome this if you want to move only on a flat plane (like along the ground).
MY preferred method (to avoid a lot of sin/cos math) is simply to save the Y position of the object before moving it, then restore it with a call to dbPositionObject(...) after the dbMoveObject(...).
Yes, the 'call to dbPositionObject' approach creates some overhead, though I'm thinking not much more than doing the sin/cos math required for movement limited to 2 axes (I have not tested this and I am no code optimization guru, heh, so I could be way off on that statement)
This is how I do it:
float fOldY = dbObjectPositionY(int ID);
dbMoveObject(int ID, fStep);
dbPositionObject(dbObjectPositionX(int ID),fOldY,dbObjectPositionZ);
If you are moving along an uneven terrain, you can use this code instead, to adjust the Y position of the moved object to the same relative height above the terrain at its new position:
int iTerrainID = 99;
int iObjectID = 999;
//get start position data
float fOldX = dbObjectPositionX(iObjectID);
float fOldY = dbObjectPositionY(iObjectID);
float fOldZ = dbObjectPositionZ(iObjectID);
//calculate height above the terrain at start
float fHeightAboveGround = fOldY - dbGetTerrainGroundHeight(iTerrainID, fOldX, fOldZ);
//move your object
dbMoveObject(iObjectID, fDistanceToMove);
//get position data for destination
float fXpos = dbObjectPositionX(iObjectID);
float fZpos = dbObjectPositionZ(iObjectID);
//calculate the new Y position for your object at its destination
float fYpos = dbGetTerrainGroundHeight(iTerrainID,fXpos,fZpos)+fHeightAboveGround;
//set the object's position using the new Y value
dbPositionObject(iObjectID, fXpos, fYpos, fZpos);
If someone who understands code efficiency better than I do would care to post a better method for doing this, please do! I'm always willing to learn from a master!
Regards,
Woozl