Ok, so here goes.
You're going to need a timer (I used the one from the FNORD project)
and an active state machine OR 3 functions:
Enter_State_Jump();
Execute_State_Jump();
End_State_Jump();
-------------------------------------------------------------------------------------
Enter_State_Jump:
Code: Select all
Enter_State_Jump()
{
m_pTimer->set(5000);//internally set jump time. Define timer in your class.
m_pTimer->stop();
m_uPlayerAction = pa_Jump;// this can be sth like "jumping=true"
m_uPlayerState = ps_ActionInProgress;//this just tells my engine not to pick up input while jumping :) You must also implement this yourself, OR you can just throw it away :)
((scene::IAnimatedMeshX*)pMesh)->setCurrentAnimation("Run");
playerNode->removeAnimators();
anim->setGravity(vector3df(0,0,0));
//ISceneNodeAnimatorCollisionResponse* anim must be a member of your class
playerNode->addAnimator(anim);
m_pTimer->start();
Execute_State_Jump();
}
Code: Select all
Execute_State_Jump()
{
core::vector3df facing( sin( playerNode->getRotation().Y * 3.1415f/180.0f ), 0, cos( playerNode->getRotation().Y * 3.1415f/180.0f ) );
facing.normalize();
facing+=facing*60;// jump height
facing.Y+=20.0f;//jump distance
playerNode->setPosition(playerNode->getPosition()+facing);
if (m_pTimer->alarm()) End_State_Jump();
}
Code: Select all
End_State_Jump()
{
playerNode->removeAnimators();
anim->setGravity(vector3df(0,-0.0008f,0));
playerNode->addAnimator(anim);
m_uPlayerAction = pa_None;//make char idle
m_uPlayerState = ps_Normal;//take input
}