walking character [ninja example]

radsun

03-01-2008 19:46:36

I really want to make a walking character but i toutrial is old and i have errors :?

My code:
Entity* hero_ent = _mgr->createEntity("ninja","ninja.mesh");
SceneNode* hero_node = _mgr->getRootSceneNode()->createChildSceneNode("ninja");
hero_node->attachObject(hero_ent);
hero_node->scale(0.05,0.05,0.05);
hero_node->translate(Vector3(0,1,0));

AxisAlignedBox aab = hero_node->getAttachedObject("ninja")->getBoundingBox();
Ogre::Vector3 min = aab.getMinimum()*hero_node->getScale();
Ogre::Vector3 max = aab.getMaximum()*hero_node->getScale();
Ogre::Vector3 center = aab.getCenter()*hero_node->getScale();
Ogre::Vector3 size(fabs(max.x-min.x),fabs(max.y-min.y),fabs(max.z-min.z));
float Radius = (size.x>size.z)?size.z/2.0f:size.x/2.0f;

OgreOde::Body* dollFeetBody = new OgreOde::Body(_world,"feet");
dollFeetBody->setMass(OgreOde::SphereMass(70*2.5,radius));
OgreOde::SphereGeometry* feetGeom = new OgreOde::SphereGeometry(radius,_world,_space);
OgreOde::TransformGeometry* feetTrans = new OgreOde::TransformGeometry(_world,_space);
hero_node->translate(Vector3(0,-radius/hero_node->getScale().y,0));
feetTrans->setBody(dollFeetBody);
feetTrans->setEncapsulatedGeometry(feetGeom);
hero_node->attachObject(dollFeetBody);


My error: :evil:
ODE INTERNAL ERROR 2
GeomTransform encapsulated object must not be in a space (...\collision_transform.cpp:133)

:cry:

Anyone can help?

rewb0rn

04-01-2008 03:48:41

Try

OgreOde::SphereGeometry* feetGeom = new OgreOde::SphereGeometry(radius,_world,0);

I think that was a matter of change some time ago.

radsun

04-01-2008 18:31:49

Thanks :) , now its working, but i have problems with moving character. :?
Rotating works

My code:
//rotate
if (input->isKeyDown(KC_J))
{
Quaternion q1 = _torso->getOrientation();
Quaternion q2(Degree(4),Ogre::Vector3::UNIT_Y);
_torso->setOrientation(q1*q2);

}
if (input->isKeyDown(KC_L))
{
Quaternion q1 = _torso->getOrientation();
Quaternion q2(Degree(-4),Ogre::Vector3::UNIT_Y);
_torso->setOrientation(q1*q2);
}

//move
if (input->isKeyDown(KC_I))
{
Quaternion q = _torso->getOrientation();
_feet->wake();
_feet->setAngularVelocity(q*Ogre::Vector3(10*cos(1.0),0,10*sin(1.0)));
}
else //stop
{
_feet->setAngularVelocity(Vector3(0,0,0));
_feet->setLinearVelocity(Vector3(0,_feet->getLinearVelocity().y,0));
}

Quaternion q = _torso->getOrientation();

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

_torso->wake();
_torso->setOrientation(Quaternion(x,Vector3::UNIT_Y,z));

:?:

rewb0rn

06-01-2008 14:47:22

have a look at the debug objects of the feet and torso geometries. does everything appear to be correct? Does the bottom sphere rotate when you hit move?

radsun

06-01-2008 17:47:46

Debug geometry is same as at the screenshot in wiki.
When i hit bottom sphere rotate but in wrong direction and its move very, very slow.

rewb0rn

06-01-2008 20:00:27

well then try a higher force and negate the value

radsun

07-01-2008 07:18:05

how can i use orientation to change force?

rewb0rn

07-01-2008 07:43:21

_feet->setAngularVelocity(q*Ogre::Vector3(-10000*cos(1.0),0,-10000*sin(1.0)));

radsun

10-01-2008 19:36:43

ok i made allmost everything,thx to you :D :D :D
i have only one more error, my ninja entity is flying a bit above the floor like on the screenshots in wiki tut http://www.ogre3d.org/wiki/index.php/Image:Wrong.jpg

this code should change it:
hero_node->translate(Vector3(0,radius/hero_node->getScale().y,0));
but char is just send into air :roll:

:?: