how can i put gravity to 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
dreamport
Posts: 188
Joined: Sun Jul 26, 2009 9:02 am
Location: philippines

how can i put gravity to objects?

Post by dreamport »

i want to add some mensters in my map, but how can i put the gravity so he can walk in the terrain correctly
opensource = freedom
<br>
how can you face the problem if the problem is your face?
CuteAlien
Admin
Posts: 9679
Joined: Mon Mar 06, 2006 2:25 pm
Location: Tübingen, Germany
Contact:

Post by CuteAlien »

First you create one of the triangle selectors for your terrain.

Then you can add an ISceneNodeAnimatorCollisionResponse to the scenenodes of your mensters(?) and pass that triangle selector to it.

Check the ISceneManager documenation for the functions needed for that: http://irrlicht.sourceforge.net/docu/cl ... nager.html

Please also check the tutorials - there are several tutorials using collision against the floor, for example the terrain tutorial.
IRC: #irrlicht on irc.libera.chat
Code snippet repository: https://github.com/mzeilfelder/irr-playground-micha
Free racer made with Irrlicht: http://www.irrgheist.com/hcraftsource.htm
dreamport
Posts: 188
Joined: Sun Jul 26, 2009 9:02 am
Location: philippines

Post by dreamport »

i think ive already done that but the meshObject is still floating...

scene::IAnimatedMesh *mesh map mesh
scene::IAnimatedMeshSceneNode *node map node
scene::IAnimatedMeshSceneNode *meshObject the monster where iw ant to put gravity...

Code: Select all

void udPutGravityToObjects(scene::IAnimatedMesh *mesh, scene::IAnimatedMeshSceneNode *node, scene::IAnimatedMeshSceneNode *meshObject, SKeyMap keymap[], scene::ISceneManager *smgr)
{
	scene::ITriangleSelector *selector = 0;
	
	if(node)
	{
		selector = smgr->createOctTreeTriangleSelector(mesh, node, 1024);
		node->setTriangleSelector(selector);
	}
	
	if(selector)
	{
		
		scene::ISceneNodeAnimator *anim = smgr->createCollisionResponseAnimator(selector, meshObject, core::vector3df(50, 100, 50),core::vector3df(0,-10,0),core::vector3df(50,100,50), 0.005);
		
		meshObject->addAnimator(anim);
		anim->drop();
	}	
}
[/code]
opensource = freedom
<br>
how can you face the problem if the problem is your face?
CuteAlien
Admin
Posts: 9679
Joined: Mon Mar 06, 2006 2:25 pm
Location: Tübingen, Germany
Contact:

Post by CuteAlien »

Hm, looks correct to me on first view. You have set some ellipsoidTranslation - maybe it is on the floor already, but just translated up so much that it seems to float? Did you try using other values for that?
IRC: #irrlicht on irc.libera.chat
Code snippet repository: https://github.com/mzeilfelder/irr-playground-micha
Free racer made with Irrlicht: http://www.irrgheist.com/hcraftsource.htm
dreamport
Posts: 188
Joined: Sun Jul 26, 2009 9:02 am
Location: philippines

Post by dreamport »

yeah, its already working, just set the value to default...

one more thing...

why is it that when i add a flystraightanimator the monster cant have its gravity...

are they overwriting each other>?

how can i put multiple animators for a scenenode?

thnx
opensource = freedom
<br>
how can you face the problem if the problem is your face?
CuteAlien
Admin
Posts: 9679
Joined: Mon Mar 06, 2006 2:25 pm
Location: Tübingen, Germany
Contact:

Post by CuteAlien »

Multiple animators often conflict simply because they try to set the same values. If one animators says "go down" and another says "follow that line" then there is an obvious conflict.
I guess you want to have some monsters walking on the floor along some line. I think you will have to write your own animator for that.
IRC: #irrlicht on irc.libera.chat
Code snippet repository: https://github.com/mzeilfelder/irr-playground-micha
Free racer made with Irrlicht: http://www.irrgheist.com/hcraftsource.htm
kburkhart84
Posts: 277
Joined: Thu Dec 15, 2005 6:11 pm

Post by kburkhart84 »

You could also just move the object yourself. Every frame, try to push the object down(gravity). Then when the monster needs tomove, instead of doing the animator, just calculate the movement yourself. Then you still keep the collision animator so they don't go through the terrain.
Post Reply