how to... drop the enemy when he is dead ?

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
paulorr29
Posts: 27
Joined: Fri Aug 27, 2010 8:23 pm
Location: Panama
Contact:

how to... drop the enemy when he is dead ?

Post by paulorr29 »

hi !

video: http://www.youtube.com/watch?v=zDfO7p64K5E

i'm testing some of AI, and attacks by the enemy, and by me player. but what can i do, when my enemy is dead ?
i'm thinking of moving the enemy to a position far far away.
example, i'm killing my enemy at (0,0,0) but when he is dead, the screen show the message victory for ... 5 seconds ? and then the enemy position change, to ( 0,-500000,0 )
works ?
or suggest me something (:
i'm trying to drop the enemy node, but the program crash !

moving to a far far far away position ? :D

-greetings
my first app with irrlicht http://youtube.com/watch?v=8OHUgciBT8E
3DModelerMan
Posts: 1691
Joined: Sun May 18, 2008 9:42 pm

Post by 3DModelerMan »

Try calling remove() on the node instead of drop(). Also, check to make sure you don't have a pointer to that node somewhere else.
That would be illogical captain...

My first full game:
http://www.kongregate.com/games/3DModel ... tor#tipjar
paulorr29
Posts: 27
Joined: Fri Aug 27, 2010 8:23 pm
Location: Panama
Contact:

Post by paulorr29 »

let me try with other simple project, in this, everytime that i call drop or remove to try to drop a node, the program crash.

this is the problem to take me to thinking to set the position node far away.
my first app with irrlicht http://youtube.com/watch?v=8OHUgciBT8E
greenya
Posts: 1012
Joined: Sun Jan 21, 2007 1:46 pm
Location: Ukraine
Contact:

Post by greenya »

Maybe try to use addToDeletionQueue:

Code: Select all

//! Adds a scene node to the deletion queue.
		/** The scene node is immediatly
		deleted when it's secure. Which means when the scene node does not
		execute animators and things like that. This method is for example
		used for deleting scene nodes by their scene node animators. In
		most other cases, a ISceneNode::remove() call is enough, using this
		deletion queue is not necessary.
		See ISceneManager::createDeleteAnimator() for details.
		\param node: Node to detete. */

		virtual void addToDeletionQueue(ISceneNode* node) = 0;
polylux
Posts: 267
Joined: Thu Aug 27, 2009 12:39 pm
Location: EU

Post by polylux »

Since the scene manager has the ownership over the scene node, and hence expects it "to be there", you're not supposed to drop it (unless you've grab()bed it before).
So, either do a

Code: Select all

yourSceneNode->remove();
as 3DModelerMan supposes, or even safer as greenya shows in his post.
beer->setMotivationCallback(this);
pera
Posts: 460
Joined: Wed May 14, 2008 1:05 pm
Location: Novi Sad, Serbia
Contact:

Post by pera »

oh yeah, you should also add "dying animation", explosion or whatever to play on kill, and remove node after that ends... :)
3DModelerMan
Posts: 1691
Joined: Sun May 18, 2008 9:42 pm

Post by 3DModelerMan »

If you want to play the animation. You could also just start the animation playing. And add a deletion animator for the time that the animation takes.
That would be illogical captain...

My first full game:
http://www.kongregate.com/games/3DModel ... tor#tipjar
paulorr29
Posts: 27
Joined: Fri Aug 27, 2010 8:23 pm
Location: Panama
Contact:

Post by paulorr29 »

yes, if you see the video of my first post, i have the animation done to the killed enemy.
but still i having problems with remove , drop, or addtodeletionQueue

for now, when the enemy is dead, i set the position how i say at first time, far away. i know this is not the best way D: !!!

someone can make me a simple example, with remove a node ?


here the code that i'm trying, some basic to trying remove

Code: Select all

#ifdef _MSC_VER
#define _CRT_SECURE_NO_WARNINGS
#pragma comment(lib, "Irrlicht.lib")
#endif
#include <irrlicht.h>
#include "driverChoice.h"

using namespace irr;

int timing=500;

int main(){
	video::E_DRIVER_TYPE driverType=driverChoiceConsole();
	if (driverType==video::EDT_COUNT) return 1;
	IrrlichtDevice* device = createDevice(driverType, core::dimension2d<u32>(640, 480), 16, false, false, false, 0);
	video::IVideoDriver* driver = device->getVideoDriver();
	scene::ISceneManager* smgr = device->getSceneManager();


scene::IAnimatedMeshSceneNode* cofre = smgr->addAnimatedMeshSceneNode(smgr->getMesh("../../media/enemy.ms3d"));
if (cofre)	{
    cofre->setMaterialFlag(video::EMF_LIGHTING, false);}

	smgr->addCameraSceneNodeFPS();


	while(device->run()){
		driver->beginScene(true, true, video::SColor(255,255,0,0));
		
		timing -= 1;
		
		if (timing < 0){
        cofre->remove();
        }
		
		smgr->drawAll(); 
		driver->endScene();}
	device->drop();
	return 0;
}
but the programa crash !!!
my first app with irrlicht http://youtube.com/watch?v=8OHUgciBT8E
Radikalizm
Posts: 1215
Joined: Tue Jan 09, 2007 7:03 pm
Location: Leuven, Belgium

Post by Radikalizm »

You keep on removing the node every frame after the timer has decreased, meaning that as soon as the timer hits -2 (with the node actually removed at -1) it will try to remove a non-existing node, causing the crash

Also it's not a good idea to base a timer on your framerate, unless you use vsync or some other syncing method
paulorr29
Posts: 27
Joined: Fri Aug 27, 2010 8:23 pm
Location: Panama
Contact:

Post by paulorr29 »

oh thanks, i dont know how i didn't see that
i change to if timing == 0
cofre ->remove
and works !

well, i'm using a variable, when the life enemy is 0 , the variable is true, and the node will remove it.
my first app with irrlicht http://youtube.com/watch?v=8OHUgciBT8E
3DModelerMan
Posts: 1691
Joined: Sun May 18, 2008 9:42 pm

Post by 3DModelerMan »

A better way than "timing == 0" would be:

Code: Select all


if (timing < 0 && cofre != 0)
{ 
 cofre->remove(); 
 cofre = 0;
}

That way if you ever change timing to a float, and actually calculate a delta time, and zero gets skipped it'll still work.
That would be illogical captain...

My first full game:
http://www.kongregate.com/games/3DModel ... tor#tipjar
randomMesh
Posts: 1186
Joined: Fri Dec 29, 2006 12:04 am

Post by randomMesh »

3DModelerMan wrote:A better way than "timing == 0" would be:

Code: Select all


if (timing < 0 && cofre != 0)
{ 
 cofre->remove(); 
 cofre = 0;
}

Better would be to check the other way round

Code: Select all

if (cofre && timing < 0)
{ 
 cofre->remove(); 
 cofre = 0;
}
since it's faster to check. (If cofre is 0, it doesn't even want to know what's behind the &&).

Even better would be to get rid of this poop and do it like real men, i.e. with a message/signal system.

http://www.boost.org/doc/libs/1_46_0/do ... gnals.html
"Whoops..."
paulorr29
Posts: 27
Joined: Fri Aug 27, 2010 8:23 pm
Location: Panama
Contact:

Post by paulorr29 »

thanks for the answers !!!! are very usuful !
my first app with irrlicht http://youtube.com/watch?v=8OHUgciBT8E
paulorr29
Posts: 27
Joined: Fri Aug 27, 2010 8:23 pm
Location: Panama
Contact:

Post by paulorr29 »

update VIDEO:
http://www.youtube.com/watch?v=wejkccdIXuQ

now i can remove an enemy :D !!
a simple test, but works :D thanks !

now i have to make better animation to the models and some particle effects to the die.

now i'm working on collisions.
what psyhic engine recommend me ?


-greetings !
my first app with irrlicht http://youtube.com/watch?v=8OHUgciBT8E
random
Posts: 158
Joined: Wed Aug 11, 2010 6:01 am

Post by random »

paulorr29 wrote: what psyhic engine recommend me ?
irrlicht has a built in collision detection, may you want to try that first?

http://irrlicht.sourceforge.net/tut007.html
http://irrlicht.sourceforge.net/phpBB2/ ... hp?t=43066


otherwise it is like the question, "i am new to driving which branch of car you reccommend..."

Newton, Physx, Bullet, Havoc and ODE are the common choices.

which one you use belongs to which implementation is easier to use with your knowledge and which kind of license you would preffer, there are wrappers and users for each of them here.
Post Reply