Jumping and collision is buggy

If you are a new Irrlicht Engine user, and have a newbie-question, this is the forum for you. You may also post general programming questions here.
Post Reply
omg_fail
Posts: 83
Joined: Wed Apr 20, 2011 1:14 pm
Location: Germany/Bavaria
Contact:

Jumping and collision is buggy

Post by omg_fail »

Hello guys.
I need some help with this.

Here is my colision :

Code: Select all

 
//Player model
        scene::IAnimatedMesh *mesh = (IAnimatedMesh*) smgr->getMesh("media/player.x");
        scene::IAnimatedMeshSceneNode *skelNode = (IAnimatedMeshSceneNode*) smgr->addAnimatedMeshSceneNode(mesh);
 
IAnimatedMesh* q3levelmesh=smgr->getMesh("test.dmf");
        ISceneNode* q3node=0;
        q3node=smgr->addOctTreeSceneNode(q3levelmesh->getMesh(0));
        ITriangleSelector* selector=0;
        q3node->setMaterialTexture(0,driver->getTexture("Floor05.jpg"));
        q3node->setMaterialFlag(EMF_LIGHTING,false);
        q3node->setPosition(vector3df(0,-100,50));
        selector=smgr->createOctTreeTriangleSelector(q3levelmesh->getMesh(0),q3node,128);
        q3node->setTriangleSelector(selector);
 
        if(selector)
        {
                ISceneNodeAnimator* triscolanim=smgr->createCollisionResponseAnimator(
                        selector,skelNode,vector3df(30,24,30),
                        vector3df(0,-grav_force,0),
                        vector3df(0.f,-0.f,0.f));
                selector->drop();
                skelNode->addAnimator(triscolanim);
                triscolanim->drop();
        }
 
Everything works fine with collision, but when I jump, it always "spawns" me at a ceratin position above me.

jumping
if (skeleton.getAnimType() == CSK_ANIM_JUMP && skeleton.getSecondMotionVariable() < 340) {
f32 wert = pow( 2.f/340.f*skeleton.getSecondMotionVariable()-1 , 2);
core::vector3df pos = player->getPosition();
pos.Y = 10.f * (-wert + 1);
player->setPosition(pos);

}
Anyone knows how to fixit ?
serengeor
Posts: 1712
Joined: Tue Jan 13, 2009 7:34 pm
Location: Lithuania

Re: Jumping and collision is buggy

Post by serengeor »

You should probably implement it using some simple body vs gravity equations.
This might help: http://www.gamedev.net/page/resources/_ ... y-faq-r694
Also, it is unclear what function: skeleton.getSecondMotionVariable() returns.
And I think you should better check for key when doing this rather then animation.

I would probably go about this like:

Code: Select all

 
if(keyispressed&&!jumping)
{
vel=500;///or any other value you like
jumping=true;
}
else if(jumping)
{
pos.y+=vel;
vel=vel-(10.0f*t);
}
if(isonground&&jumping)
{
jumping=false;
}
 
Don't really know if this would work correctly though.

You should probably take a look at some opensource games to see how others have done it.
Working on game: Marrbles (Currently stopped).
omg_fail
Posts: 83
Joined: Wed Apr 20, 2011 1:14 pm
Location: Germany/Bavaria
Contact:

Re: Jumping and collision is buggy

Post by omg_fail »

Ok I'm sorry I forgot to write the code for the function.

Code: Select all

 
u32 cSkeleton::getSecondMotionVariable() {
        return kTemp;
}
 
Thanks for the link, I'll have a look at it.
Your code suggestion is probably better than mine, I think i might going to use it, when my current code finally works.
Post Reply