Dibalo
12-05-2007 16:42:11
Hi.
I got a problem with character movement by addForce. My characer walks and stops walking as I want but the problem is that when I stop the walking, character "jumps" This happens when character is walking in the middle of hill. The bigger angle of the hill the higher jump character makes. If he´s walking on the flat area, jump will not happen when stopping. I hope you could help me with this issue. Here is my current moving callback:
When the character is moving the variable isMoving is true. I´ll change it to true by pressing keyboard key.
I´m making my character with this code:
Please, if you want more details, I´d tell them happily.
I got a problem with character movement by addForce. My characer walks and stops walking as I want but the problem is that when I stop the walking, character "jumps" This happens when character is walking in the middle of hill. The bigger angle of the hill the higher jump character makes. If he´s walking on the flat area, jump will not happen when stopping. I hope you could help me with this issue. Here is my current moving callback:
void _callback(Body* b)
{
Real speed = 20;
Vector3 vel = b->getVelocity();
vel.y = 0;
mMove = ((mNode->getOrientation() * Vector3::NEGATIVE_UNIT_Z * (isMoving*speed))-vel)/b->getWorld()->getTimeStep();
b->addForce( mMove * mMass );
b->addForce( Vector3(0,-9.81,0) * mMass );
isMoving = false;
}When the character is moving the variable isMoving is true. I´ll change it to true by pressing keyboard key.
I´m making my character with this code:
_Character(const String& mesh)
: mMove(Vector3::ZERO), isMoving(false)
{
System* sys = System::getSingletonPtr();
mNode = sys->SceneManager->getRootSceneNode()->createChildSceneNode();
Entity* ent = sys->SceneManager->createEntity( "__DEV_Character_Ent__", mesh );
mNode->attachObject( ent );
mNode->setScale(0.07,0.07,0.07);
Collision* col = new OgreNewt::CollisionPrimitives::Ellipsoid( sys->PhysXworld, Vector3(1.5,.3,.3) );
mBody = new Body( sys->PhysXworld, col );
OgreNewt::BasicJoints::UpVector* joint = new OgreNewt::BasicJoints::UpVector( sys->PhysXworld, mBody, Vector3::UNIT_Y );
mDirJoint = new OgreNewt::BasicJoints::UpVector(sys->PhysXworld, mBody, Vector3::UNIT_X);
delete col;
mMass = 2;
mInertia = OgreNewt::MomentOfInertia::CalcEllipsoidSolid(mMass,Vector3(1.5,0.3,0.3));
mBody->attachToNode( mNode );
mBody->setCustomForceAndTorqueCallback<_Character>( &_Character::_callback, this );
mBody->setMassMatrix( mMass, mInertia );
mBody->setPositionOrientation( Vector3(-100,150,80), Quaternion() );
mBody->setAutoFreeze(0);
OgreNewt::MaterialID* mat = new OgreNewt::MaterialID( sys->PhysXworld );
OgreNewt::MaterialPair* pair = new OgreNewt::MaterialPair( sys->PhysXworld, mat, sys->PhysXworld->getDefaultMaterialID() );
pair->setDefaultElasticity(0);
pair->setDefaultFriction(0,0);
mBody->setMaterialGroupID( mat );
Keyboard& keys = Keyboard::getSingleton();
keys.registerEvent( KeyData(OIS::KC_U, 1), Keyboard::Event(&_Character::move, this) );
}Please, if you want more details, I´d tell them happily.