I was looking at the code of CCameraFPSSceneNode. I want to handle movement on my own so I use my own position component.
Here is parts of my code:
This one is from the update() function of my CameraFPS.
Code: Select all
if( Flag[FLAG_INIRRSCENE] )
{
//Update the direction of Position component from Irrlicht
vector3df camTarget( irrSceneNode_->getTarget().X,
irrSceneNode_->getTarget().Y,
irrSceneNode_->getTarget().Z );
cmpPos_->setTarget( camTarget );
//Update the position of Irrlicht camera from position component
VEC3D camPosition = cmpPos_->getPosition();
irrSceneNode_->setPosition( irr::core::vector3df( camPosition.x, camPosition.y, camPosition.z ) );
}
Code: Select all
//Setting camera speed
if( key == KEY_UP )
{
cmpPos_->setSpeed( 0.5f );
}
else if( key == KEY_DOWN )
{
cmpPos_->setSpeed( -0.5f );
}
Code: Select all
void Position::setTarget( VEC3D target )
{
direction_ = NORMALIZED(target - position_);
}
Code: Select all
...
position_ += direction_*speed_*timeFactor;
...
Basically if I use a really small value, like 0.5f, it works fine. However once I go beyond that, I think what happens is since I'm setting the position to somewhere beyond the target, the node doesn't allow it. At first I was thinking it was a division by zero while normalizing the direction vector but I shouldn't get a div/0 if I set the speed to something like 100.0f. Sadly, it still doesn't work.
Any ideas?
Thanks a lot.