Problems with player

russianStalker

16-08-2010 11:21:20

Hello everyone.
I have some problem.
My player is jumping on the world like a ball, sliding on the floor. I tried to set a pair of materials, but I failed. It's not change anything. Please help me.
Actor::Actor(std::string name, std::string path, Vector3 position)
{
Vector3 actorSize(80,200,80);
position.y += actorSize.y/3;
mainNode = engine->sceneMgr->getRootSceneNode()->createChildSceneNode(name);
actorNode = mainNode->createChildSceneNode (name + "_actor", Vector3(0, -actorSize.y/2, 0));
entity = engine->sceneMgr->createEntity(name, path);
actorNode->attachObject(entity);
cameraNode = actorNode->createChildSceneNode (name + "_camera", Vector3(0, 200, 200));
engine->camera->lookAt(mainNode->getPosition());
cameraNode->attachObject(engine->camera);
velocity = strafe = 0;
OgreNewt::CollisionPrimitives::Box* col = new OgreNewt::CollisionPrimitives::Box(engine->world->physWorld, actorSize, 0);
body = new OgreNewt::Body(engine->world->physWorld, OgreNewt::CollisionPtr(col));
body->attachNode(mainNode);
double mass = actorSize.x*actorSize.y*actorSize.z*2.5;
Vector3 inertia, offset;
col->calculateInertialMatrix (inertia, offset);
body->setMassMatrix(mass, inertia*mass);
body->setPositionOrientation(position, Quaternion::IDENTITY);
body->setCustomForceAndTorqueCallback<Actor>(&Actor::forceCallback,this);

const OgreNewt::MaterialID* defaulted = engine->world->physWorld->getDefaultMaterialID();
body->setMaterialGroupID(defaulted);
OgreNewt::MaterialID* ground_material_id = new OgreNewt::MaterialID(engine->world->physWorld);
engine->world->body->setMaterialGroupID(ground_material_id);

OgreNewt::MaterialPair* pair1 = new OgreNewt::MaterialPair(engine->world->physWorld, defaulted, defaulted);
OgreNewt::MaterialPair* pair2 = new OgreNewt::MaterialPair(engine->world->physWorld, defaulted, ground_material_id);
pair2->setDefaultElasticity(0.5f);
pair2->setDefaultFriction(1, 2);
pair2->setDefaultSoftness(0.5);
delete col;
}

void Actor::forceCallback(OgreNewt::Body* mBody, float timeStep, int threadIndex)
{
Quaternion orient;
Vector3 pos;

mBody->getPositionOrientation(pos, orient);

Vector3 force(0,-9.8,0);
Vector3 force2(0,-9.8,0);
Ogre::Real mass;
Ogre::Vector3 inertia;
mBody->getMassMatrix(mass, inertia);

Ogre::Quaternion q;
Ogre::Vector3 qq,s;
Vector3 direction = (orient * Vector3::NEGATIVE_UNIT_Z);
Vector3 poo2 = (orient * Vector3::NEGATIVE_UNIT_X);
qq = direction;
s = poo2;
Ogre::Vector3 V0 = mBody->getVelocity();
Ogre::Vector3 V1(qq * velocity);
Ogre::Vector3 V2 (s * strafe);
Ogre::Vector3 acel = (V1 - V0);
Ogre::Vector3 acel2 = (V2 - V0);
acel = acel * 0.5f;
acel2 = acel2 * 0.5f;

force.x = acel.x;
force.z = acel.z;

force2.x = acel2.x;
force2.z = acel2.z;

Vector3 x = orient.xAxis();
Vector3 y = orient.yAxis();
Vector3 z = orient.zAxis();

mBody->setPositionOrientation(mBody->getPosition(), Quaternion(x,Vector3::UNIT_Y,z));

mBody->setOmega(Vector3(0, engine->frameListener->mRotateX.valueRadians()*500,0));
mBody->setForce(force*mass);
mBody->addForce(force2*mass);
}

z789017890

16-08-2010 13:35:23

can your player jumping?

russianStalker

16-08-2010 15:03:17

No, when my player is faced with a wall, he starts to jump on the map, bouncing off it.
Sorry for my terrible English.

majc

20-08-2010 18:01:30

If you want use my code:

viewtopic.php?f=4&t=13268