Collision demo - set collision to characters

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
WhyMe
Posts: 10
Joined: Sat Jan 26, 2013 5:31 pm

Collision demo - set collision to characters

Post by WhyMe »

Hello.
I readed the collision demo, and tried set collision to other characters which was added.
At the beginning I try to faerie character, but she is going down by gravitation. I think, i just forget something. :(

This is a fragment code modified by me:

Code: Select all

 // Add an MD2 node, which uses vertex-based animation.
    node = smgr->addAnimatedMeshSceneNode(smgr->getMesh("faerie.md2"),
                        0, IDFlag_IsPickable | IDFlag_IsHighlightable);
    node->setPosition(core::vector3df(-90,-15,-140)); // Put its feet on the floor.
    node->setScale(core::vector3df(1.6)); // Make it appear realistically scaled
    node->setMD2Animation(scene::EMAT_POINT);
    node->setAnimationSpeed(20.f);
    material.setTexture(0, driver->getTexture("faerie2.bmp"));
    //material.setFlag(video::EMF_NORMALIZE_NORMALS,true);
    //material.setFlag(video::EMF_LIGHTING, true);
    material.Lighting = true;
    material.NormalizeNormals = true;
    node->getMaterial(0) = material;
 
    // Now create a triangle selector for it.  The selector will know that it
    // is associated with an animated node, and will update itself as necessary.
    selector = smgr->createTriangleSelector(node);
 
    if(selector)
    {
        node->setTriangleSelector(selector);
        scene::ISceneNodeAnimator *anim = smgr->createCollisionResponseAnimator(selector, node, core::vector3df(10,10,10),
                                                                                core::vector3df(0,-10,0), core::vector3df(0,10,0));
 
        node->addAnimator(anim);
        anim->drop();
        selector->drop(); // We're done with this selector, so drop it now.
    }
Well, I tried to set Collision Response Animator, as like in case of Camera Scene Node.
WhyMe
Posts: 10
Joined: Sat Jan 26, 2013 5:31 pm

Re: Collision demo - set collision to characters

Post by WhyMe »

At least I made it, but I would like to know more.

I added collision to two characters, like that:

Code: Select all

selector = smgr->createOctreeTriangleSelector(node->getMesh(), node, 128);
 
    core::aabbox3d<f32> box = node->getBoundingBox();
    core::vector3df radius = box.getExtent();
 
    if(selector)
    {
        node->setTriangleSelector(selector);
        scene::ISceneNodeAnimator *anim = smgr->createCollisionResponseAnimator(selector, camera, radius,
                                                                               core::vector3df(0,0,0), core::vector3df(0,-10,0));
 
        camera->addAnimator(anim);
        anim->drop();
        selector->drop(); // We're done with this selector, so drop it now.
    }
 
    // And this B3D file uses skinned skeletal animation.
    node = smgr->addAnimatedMeshSceneNode(smgr->getMesh("ninja.b3d"),
                        0, IDFlag_IsPickable | IDFlag_IsHighlightable);
    node->setScale(core::vector3df(10));
    node->setPosition(core::vector3df(-75,-66,-80));
    node->setRotation(core::vector3df(0,90,0));
    node->setAnimationSpeed(8.f);
    node->getMaterial(0).NormalizeNormals = true;
    node->getMaterial(0).Lighting = true;
    // Just do the same as we did above.
    selector = smgr->createTriangleSelector(node);
 
 
    box = node->getBoundingBox();
    radius = box.MaxEdge - box.getCenter();
 
    if(selector)
    {
        node->setTriangleSelector(selector);
        scene::ISceneNodeAnimator *anim = smgr->createCollisionResponseAnimator(selector, camera, core::vector3df(15,70,15),
                                                                                core::vector3df(0,0,0));
        camera->addAnimator(anim);
        anim->drop();
        selector->drop();
    }

I understand, that the world is this character, which I want to interact with collision, and Scene Mode is camera, because I moved it. But, why if I set gravity (e.g. (0,-10,0), camera moved down ??
Did I understood, that now I set collision for my movement, of my camera, but other objects can move over me ? Do I need set for them separately collision detection ?
From other hand, is in the Irrlicht Engine added physics, or I need to add to project other libraries and sources ?
darksmaster923
Posts: 51
Joined: Tue Jan 02, 2007 11:04 pm
Location: huntington beach

Re: Collision demo - set collision to characters

Post by darksmaster923 »

I'm not really sure what the question is. You ask why the character moves down but you're setting gravity in the createCollisionResponseAnimator.

Irrlicht doesn't really have physics integrated, you should use a seperate physics library
Programmers are merely tools to convert caffeine into code.
WhyMe
Posts: 10
Joined: Sat Jan 26, 2013 5:31 pm

Re: Collision demo - set collision to characters

Post by WhyMe »

Sorry, the english is not my native speak language, so it is very hard to say something.

About physics, ok, after learn how Irrlicht works, I will try maybe Newton, because I seen some tutorials.

About collision. I am little confused, why I should node pointed to camera, not to character, and why, if I set the gravity to this character for interact with collision, my camera goes down by floor.

I have hope that I wrote it correctly.
Regards.
Post Reply