A VERY rough way to do jumping

A forum to store posts deemed exceptionally wise and useful
Post Reply
Cristian

A VERY rough way to do jumping

Post by Cristian »

Ok, I had a small contest so I had to make ZFOTW (my game) official, and had to improve it. And, among other things I added jumping. I know this has been treated before, but I did not use Newton or ANY other phisycs engine (no time,had only 3 days) :)

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();
}
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        
    }
Ok, this concludes today's meeting. You can always find me at crstn_udrea@yahoo.com, if you want to drop a line, go ahead, just DON'T SPAM :D
Guest

Post by Guest »

Can you make a small demo with this, please.

Thank you.
pyrocrickett
Posts: 3
Joined: Fri Nov 11, 2005 2:31 am
Location: Notre Dame, IN

Demo?

Post by pyrocrickett »

Yeah, a demo would be greatly appreciated!
==========
pyroCrickett
--------------------
there's no place like 127.0.0.1
Cristian
Posts: 55
Joined: Fri Nov 25, 2005 12:02 pm

Post by Cristian »

OFFTOPIC: It's me. I'm registered now :)

Back to the topic:

Go to http://zfotw.sourceforge.net.

You'll find the sourcecode to ZFOTW there. It has this integrated inside the "external\IPlayerClass.cpp".
Post Reply