Animated objects with a collision response animator...

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
christianclavet
Posts: 1638
Joined: Mon Apr 30, 2007 3:24 am
Location: Montreal, CANADA
Contact:

Animated objects with a collision response animator...

Post by christianclavet »

Hi, Got some problems with animated object (IAnimated scene node - Skinned mesh) that has a collision response animator on it.

I move the node manually with a setPosition() command. The problem is that the object will not move at the desired coordinates (small offset incrementing each time). If I remove the collision response animator from the animated model, the setPosition work perfectly and the position is not altered. I need the collision animator mainly for checking collision with other objects.

I've tried to force an absolute position update using this:

Code: Select all

node->updateAbsolutePosition();
That fixed the problem partially, the position don't look to be altered, its look like the collision response is "fighting" with this and the movement (position change) is jerky.

Then I tried this instead:

Code: Select all

node->onAnimate(0);
This make the movement (position changes) smooth again, but since it's skinned mesh. Something make the mesh animation stop.

Is there a way I could keep the position change to stay smooth and keep the skinned mesh animating while keeping the collision response animator?
RuggJack93
Posts: 39
Joined: Mon Sep 06, 2010 5:09 pm
Location: Italy

Post by RuggJack93 »

I had a similar problem sometime ago.
I solved it by removing the collision response animator to my node, changing position with setPosition() and re-creating the collision response animator.
It seems that when you set a new position, the animator does not update properly ,so you have to "reset it" somehow.
Hope it helps :).
christianclavet
Posts: 1638
Joined: Mon Apr 30, 2007 3:24 am
Location: Montreal, CANADA
Contact:

Post by christianclavet »

Thanks, I've tried that, but the same symptom, as when I used "node->updateAbsolutePosition();". Also, not sure removing the collision when I want to move it going to help, as I put it there to check for collisions when moving the character.

I don't know what to do next. Perhaps doing my own small character collision system. I'm thinking of something really basic right now (getting the bounding box to get the radius of the object, then check then all objects for a distance), but I still think it's overkill for something that I don't understand.)

EDIT:
Here is the current code:

Code: Select all

void setPosition(vector3df pos)
{
	core::list<ISceneNodeAnimator*>::ConstIterator begin = node->getAnimators().begin(); 
	core::list<ISceneNodeAnimator*>::ConstIterator end = node->getAnimators().end(); 
	for(int it=0; begin != end; ++it ) 
	{ 
		ISceneNodeAnimator* pAnim = *begin; 
		if( pAnim->getType() == ESNAT_COLLISION_RESPONSE ) 
		{ 
		       node->removeAnimator(pAnim);
		       node->setPosition(pos);
		       node->updateAbsolutePosition();
		       node->addAnimator(pAnim);
		       break; 
		} 
		
	}
	
}
This does the same problem. So Im sure im doing something wrong because I don't understant the thing. I've tried with and without the "updateAbsolutePosition". Would I need to set a flag to put back the animator on the next render?

This seem to be subtle (jerky movement) and seem to affect more when the nodes that were scaled. If the animator is not present, the node movement is ok, but I need it so characters don't overlap.

Here is what happen when the collision is on a animated scene node and i move that node with a setPosition command:

Image

If you look at the picture, all characters should stand on their Y at 0. This one is really set at 0 but at each iteration of the setPosition command, it goes below. Retrieving the absolutePosition reveal the problem and I'm unable to fix it. (The only "fix" is to remove the animator (collision response), then everything is ok, except that the "NPCS" will cross each other with no way to detect if they collide.

Is there a way to fix this or I need to use another collision detection? (creating my own?)
RuggJack93
Posts: 39
Joined: Mon Sep 06, 2010 5:09 pm
Location: Italy

Post by RuggJack93 »

Here's my code:

Code: Select all

sphere->removeAnimator(collision);
sphere->setPosition(spawnPoint);
			collision = smgr->createCollisionResponseAnimator(worldSel, sphere, core::vector3df(6,6,6), core::vector3df(0,0,0));
			sphere->addAnimator(collision);
			collision->drop();
This is what I ment when i said "re-create", I actually tell the scene manager to create a new animator over the old one.
From what i've understood from your code(correct me if i'm wrong), you simply remove and add the animator, keeping always the same "pAnim", which doesn't update correctly.
christianclavet
Posts: 1638
Joined: Mon Apr 30, 2007 3:24 am
Location: Montreal, CANADA
Contact:

Post by christianclavet »

Thanks for the code, I will surely try that!

[EDIT]
OK! Found the problem and fixed it! I was using the same meta selector for all the NPC. When I was creating the animator, the meta selector contained the triangle of the mesh it was applied on.

Now when I'm setuping the scene I recreate the meta selector each time, and remove the triangle selector of the current node from it, instead of reusing the same meta selector. Now the character move correctly (even when they are scaled)

here is my code:

objects are my nodes list

Code: Select all

IMetaTriangleSelector* createMeta()
{
	ISceneManager* smgr = Device->getSceneManager();
	IMetaTriangleSelector* meta=smgr->createMetaTriangleSelector();
	ITriangleSelector* triangle=0;

	// Put all the triangle selector into one meta selector.
    for(int i=0;i<(int)objects.size();i++)
    {
		triangle = objects[i]->getTriangleSelector();
		meta->addTriangleSelector(triangle);
     }
	return meta;
}

void initializeCollisions()
{
	ISceneManager* smgr = Device->getSceneManager();
	
	// Create the collision response animator for each NPC.
	for(int i=0;i<(int)objects.size();i++)
    {
		if (objects[i]->getType()==OBJECT_TYPE_NPC)
		{
			IMetaTriangleSelector* meta = createMeta();
			meta->removeTriangleSelector(objects[i]->getTriangleSelector());
			ISceneNodeAnimatorCollisionResponse* coll = smgr->createCollisionResponseAnimator(meta,objects[i],vector3df(0.2f,0.5f,0.2f),vector3df(0,0,0));
			objects[i]->addAnimator(coll);
			meta->drop();
		}
	}
	
}
Jono
Posts: 4
Joined: Wed Dec 01, 2010 11:02 pm
Location: SOUTH AFRICA

Collision Response supposed to be easy

Post by Jono »

:?

Im going to retry all samples included with irr 1.7 just seem to be struggling
Post Reply