Falling attached objects

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
Lunacore
Posts: 18
Joined: Sun May 30, 2010 4:01 pm
Location: Berlin (Germany)

Falling attached objects

Post by Lunacore »

My new problem, i get, is the following:
On setPosition, my player and all objects attached on it will change it's position, but while my player is falling due to gravity, the attached objects are
falling slower until the player reaches the ground.

Image

Code: Select all

//Load meshes
IMesh* Hairs = smgr->getMesh("../models/Hair.obj");
IAnimatedMesh* MeshModel0 = smgr->getMesh("../models/player.ms3d");
IMesh* MeshModel1 = smgr->getMesh("../models/Sword.obj");
IMesh* MeshModel2 = smgr->getMesh("../models/Sword.ms3d");


//Load player
Player[0] = smgr->addAnimatedMeshSceneNode(MeshModel0);
Player[0]->setFrameLoop(31,37); Player[k]->setAnimationSpeed(15);
Player[0]->setTransitionTime(0.2);
//Create collisions
anim[0] = smgr->createCollisionResponseAnimator( //Kollision für Spieler i einfügen
										selector, Player[0], core::vector3df(30,100,30),
										core::vector3df(0,-3,0), //gravity
										core::vector3df(0,-100,0));
Player[0]->addAnimator(anim[0]);

//Add hair
Head             = Player[0]->getMS3DJointNode("Head");
StaticObjects[0] = smgr->addMeshSceneNode(Hairs);
StaticObjects[0] -> setRotation(vector3df(-90,0,90));
StaticObjects[0] -> setPosition(vector3df(-3,0,-13));
Head             ->addChild(StaticObjects[0]);

//Add Weapons
Weapon[0] = smgr->addMeshSceneNode(MeshModel1);
Weapon[1] = smgr->addMeshSceneNode(MeshModel2);           
//Get pointer
RechteHand[0] = Player[0]->getMS3DJointNode("WeaponR");
LinkeHand[0] = Player[0]->getMS3DJointNode("WeaponL");
//Add weapon to pointer
RechteHand[0]->addChild(Weapon[0]); 
LinkeHand[0]->addChild(Weapon[1]);
When i move along X/Z-axes, the attached models will be on their correct position. The problem only occurs at Y-axis during gravity.
ChaiRuiPeng
Posts: 363
Joined: Thu Dec 16, 2010 8:50 pm
Location: Somewhere in the clouds.. drinking pink lemonade and sunshine..

Post by ChaiRuiPeng »

how are you "applying gravity"

simply through setPosition() applied ONLY to parent?

are there any rotations you are applying to parent?
Lunacore
Posts: 18
Joined: Sun May 30, 2010 4:01 pm
Location: Berlin (Germany)

Post by Lunacore »

I move only through setPosition() and setRotation on Player[0], weapons and hair will move automatically. This is not the problem.

As shown above I apply the gravity only to my player character, because the position of the attached objects are relpative to the characters position.

Code: Select all

anim[0] = smgr->createCollisionResponseAnimator(
                              selector, Player[0], core::vector3df(30,100,30),
                              core::vector3df(0,-3,0), //gravity
                              core::vector3df(0,-100,0));
Player[0]->addAnimator(anim[0]); 
While he is falling, the mesh of the character falls faster then attached objects..
shadowslair
Posts: 758
Joined: Mon Mar 31, 2008 3:32 pm
Location: Bulgaria

Post by shadowslair »

You need to update all children transformations. Try creating some help function to update all children recursively. Put it on place where you`re done moving/rotating your character. Sth like (untested, but should(™) work):

Code: Select all

void updateChildrenTransf(scene::ISceneNode *node)
{
   node->updateAbsolutePosition();
   core::list<scene::ISceneNode*>::ConstIterator it = node->getChildren().begin();
   for (; it != node->getChildren().end(); ++it)
   {
      updateChildrenTransf((*it));
   }
}
May be a bit slower, but should fix your problem.
"Although we walk on the ground and step in the mud... our dreams and endeavors reach the immense skies..."
Lunacore
Posts: 18
Joined: Sun May 30, 2010 4:01 pm
Location: Berlin (Germany)

Post by Lunacore »

I updated all nodes (parents and children), but the problem still exist.
Here a little cutscene, what I mean: Youtube

Another problem:
On the first program start, only the hair has the exact position while falling (like in the video).
On another program start without changing anything, only the shield has the exact position and the hair is like the sword above the player while falling.
Is this a bug by Irrlicht? o0
shadowslair
Posts: 758
Joined: Mon Mar 31, 2008 3:32 pm
Location: Bulgaria

Post by shadowslair »

Ah, just spotted you`re using collision animator. Most probably it`s causing the problem, because it`s affecting the node position right before being rendered, so the bone children are being positioned one frame later, because most probably they`re not in the ISceneNode::Children list. Unfortunately I personally cannot think of an easy way around that, except to not use the build-in collision animator, but some other system instead. May be wrong though- it`s been a while since I used the irr collision.

About the other problem- it may be caused by many things like using uninitialized values (for ex. initialized, but like: int myValue; then used, before being set to some real value) or sth else. And no, I doubt its an Irrlicht bug, because I have never had such problems. But you`re free to use the debugger for that.
"Although we walk on the ground and step in the mud... our dreams and endeavors reach the immense skies..."
Post Reply