yes, with collision frame into floor it's normal he tries to put its own collision shape out the floor by goes down. you should try to don't put the collision frame into the floor. for example use EOM_PRECISE in setFrictionModel or simply reduce the gravity when courching. however this is a bug of newton, if you set a force too high and the body is very close to a wall\floor , the body will go trough the floor\wall for a certain time
right I'll play with that now and see if I can get it to work.
but is there a floor below your character when you try to jump?
Yes.
I decided since I needed an 'isJumping()' function anyway I'd write it and try to use that to make my character jump. It works just fine. Here is the code for it:
Code: Select all
bool irr::newton::ICharacterController::isJumping(irr::f32 distanceFromFloor) {
core::aabbox3d<f32> box=this->calculateAABB();
core::line3d<f32> line(box.MinEdge,core::vector3df());
line.end=line.start;
line.end.Y-=999999.9f;
irr::newton::SIntersectionPoint i_point=
this->world->getCollisionManager()->getCollisionFirstPointEx(line);
if(i_point.body!=NULL) {
irr::f32 distance=i_point.point.getDistanceFrom(line.start);
if(distance <= distanceFromFloor) {
core::vector3df net_applied_force=this->getNetAppliedForce();
/*
//DEBUG
core::stringc m;
m+=(double)net_applied_force.Y;
this->world->getIrrlichtDevice()->getLogger()->log(m.c_str());
*/
this->world->getUtils()->round(net_applied_force,1);
/*
//DEBUG
m="";
m+=(double)net_applied_force.Y;
this->world->getIrrlichtDevice()->getLogger()->log(m.c_str());
*/
if(net_applied_force.Y==0.0f)
//can jump!!
return false;
else
return true;
}//distance
}//body!=NULL
return false;
}
You might want to include it in your next version as some people may want to disable movement while jumping, incorporate flips, etc...
feel free to tell me if I screwed up the code XD I think something may be wrong with it as when I set the value to 10 or lower it is always true...
That also means that the part of jump() that isn't working for me is the code that actually makes the body jump.
EDIT: my crouching code is... closer. He jumps a little bit the first time, a little less the second time, and not at all afterwards. Crouching while in the air does play havoc with gravity... but thats not a problem because my game doesn't need crouching in the air. Heres what it is at now...
Code: Select all
if(gameManager->getDownKey())
{
p1body->setScale(vector3df(0.5f,0.5f,0.5f));
pworld->getUtils()->avoidRotationOnAllAxis(p1body);
p1node->setScale(vector3df(1,1,1));
if(p1body->crouch(0.5))
{
pworld->getUtils()->avoidRotationOnAllAxis(p1body);
}
}
else if(p1body->stand(6))
{
p1body->addForceContinuous(vector3df(0,0,0));
pworld->getUtils()->avoidRotationOnAllAxis(p1body);
p1body->addForceContinuous(vector3df(0,-30.0f,0));
}