Hi. I'm trying to move a character to a specified position, similar to waypoints, but the character seems to move in an entirely different position than the one specified. Can you please look through the code and see if you can give me any pointers.
// u32 timeSinceLastLoop is the number of ms since the last animation frame
// f32 speed is in units per ms
f32 distance = (f32)timeSinceLastLoop * speed;
vector3df direction(0,0,1); // the direction your node is facing
pos = node->getPosition();
node->getRelativeTransformation().rotateVect(direction);
pos += direction * distance;
node->setPosition(pos);
// Move an object to a destination. vector3df movepos is the destination
void CZombie::move()
{
vector3df oldPos = node_zombie->getPosition();;
vector3df tPos;
triangle3df triout;
bool gravity = true;
if(oldPos.getDistanceFrom(movepos) >= 100)
{
vector3df direction = (movepos-oldPos).normalize();
// The minus 90 could be that my character is rotated on import
f32 angle = direction.getHorizontalAngle().Y-90;
node_zombie->setRotation(vector3df(0,angle,0));
// Translation position - Movement should be framerate independent.
tPos.Z=direction.Z*4.1f;
tPos.X=direction.X*4.1f;
// Tryout collision - CCollision getcollision is the triangleselector for the environment
vector3df dPos = CGameMain::getSceneManager()->getSceneCollisionManager()->getCollisionResultPosition(CCollision::getCollision(),
oldPos, vector3df(10.0f,10.0f,10.0f), tPos, triout, gravity, 0.05f, vector3df(0.0f,-3.0f,0.0f));
// Setposition
node_zombie->setPosition(dPos);
waypoint = false;
}
else
{
waypoint = true;
}
}
// u32 timeSinceLastLoop is the number of ms since the last animation frame
// f32 speed is in units per ms
f32 distance = (f32)timeSinceLastLoop * speed;