IrrWizard?

Announce new projects or updates of Irrlicht Engine related tools, games, and applications.
Also check the Wiki
area51
Posts: 338
Joined: Thu Mar 18, 2004 10:20 pm
Location: UK
Contact:

Post by area51 »

Adding doors.

Your door should probably be in the Init() function of a subclass of the CGamePlayState, like CGameStateLevel01 or whatever. (because its level specific, not common to all levels)

A door will be the same as a health or ammo item, but instead it's type will be a GAME_ITEM_DOOR. Look in:

Code: Select all

  void CGameStateLevel01::addHealthPickups(CGameManager* pManager)
It creates a CGameItem object, adds the mesh, sets the trigger radius, sets the type, then adds the object to the CGameItemManager

The actual code to animate the door, animation call back and stuff is there already. look here:

Code: Select all

void CGameItemManager::processTriggerDoor(CGameManager* pManager, CGameItem* pItem)
Just change to your animation frames.

Good luck
________
YAMAHA CS-80 HISTORY
Last edited by area51 on Fri Feb 25, 2011 12:06 am, edited 1 time in total.
Dutch
Posts: 12
Joined: Tue Aug 22, 2006 9:45 pm
Location: UK

door

Post by Dutch »

Hi area51

thanks for quick reply.

Ok I will go that route. I thought it would be possible just to import a doormesh from milkshape and put a flystraight animator on it with a trigger region. haven't found out yet how to just animate a primitive in milkshape without using bones

thanks

dutch
area51
Posts: 338
Joined: Thu Mar 18, 2004 10:20 pm
Location: UK
Contact:

Post by area51 »

You could put your FlyStraightAnimator code in the processTriggerDoor() function instead of animating the mesh if that's easier.
________
How I Met Your Mother Dicussion
Last edited by area51 on Fri Feb 25, 2011 12:07 am, edited 1 time in total.
Dutch
Posts: 12
Joined: Tue Aug 22, 2006 9:45 pm
Location: UK

doors

Post by Dutch »

Hi area51,

Managed to make an md2 animation of a sliding door with milkshape.

I'm getting a bit confused now though. At the moment i have the following code in my Game level init():

Code: Select all

scene::IAnimatedMeshSceneNode* slideNode;
	scene::IAnimatedMesh* slide = pManager->getSceneManager()->getMesh("media/door.md2");
	slideNode = pManager->getSceneManager()->addAnimatedMeshSceneNode(slide);
	slideNode->setMaterialFlag(EMF_LIGHTING, false);
	slideNode->setMaterialTexture( 0, pManager->getDriver()->getTexture("media/stripes.jpg") );
	slideNode->setRotation(core::vector3df(0,90,0));
	slideNode->setScale(core::vector3df(1.8,1.8,1));
	slideNode->setPosition(core::vector3df(890, 510, -10));
   slideNode->setLoopMode(false);
	scene::ITriangleSelector* slideSelector = pManager->getSceneManager()->createTriangleSelectorFromBoundingBox(slideNode); 
        if(slideSelector) 
		    pManager->getMetaSelector()->addTriangleSelector(slideSelector);
I stop the animation with the loopmode but how do i get the animation running with a trigger??

I have tried various ways including using the md2 as a Doorpickup and not with the code above ie:

Code: Select all

//! Add DOOR  to level
void CGameStateLevel02::addDoorPickups(CGameManager* pManager)
{
	// load in pickups, DOOR
	for (u32 i=0; i < 5; i++) 
	{
		scene::IAnimatedMesh* doorMesh = 0;
		doorMesh = pManager->getSceneManager()->getMesh("media/door.md2");
		CGameItem* door = new CGameItem(GAME_ITEM_DOOR); 
		door->setMeshNode(pManager->getSceneManager()->addAnimatedMeshSceneNode(doorMesh));
		if (door->getMeshNode())
		{
			door->getMeshNode()->setMaterialTexture(0, pManager->getDriver()->getTexture("media/intro.jpg"));
			door->getMeshNode()->setPosition(pManager->getPathManager()->getWaypointAt(1));
			door->getMeshNode()->setScale(core::vector3df(.5,.5,.5));
			door->getMeshNode()->setMaterialFlag(video::EMF_LIGHTING, false);
			door->getMeshNode()->addShadowVolumeSceneNode();
			door->getMeshNode()->setID(GAME_ITEM_DOOR); //OBJECT_PICKUP
			door->setTriggerRegion(70);//reduce radius due to model size

		}
	}
}
I got it working this way but can't seem to put a triangleselector to it for collisions. (I'm going straight through it) and also, the trigger won't reset.

the code in the gameitemmanager is as follows:

Code: Select all

//! DOOR Trigger activated
void CGameItemManager::processTriggerDoor(CGameManager* pManager, CGameItem* pItem)
{
	// reset trigger at animation end
		m_bAnimationEnd = false;
		pItem->getMeshNode()->setLoopMode(false);
        pItem->getMeshNode()->setAnimationEndCallback(this);
	    pItem->getMeshNode()->setAnimationSpeed(30);
        pItem->getMeshNode()->setFrameLoop(0, 220);
		pItem->setLocalInt("door_open", 0); // testing using NWN style softcoded variables
}

I hope you understand what i mean. I am a newbie when it comes to c++ (have a little experience with Delphi, but I like a challange

regards

dutch
area51
Posts: 338
Joined: Thu Mar 18, 2004 10:20 pm
Location: UK
Contact:

Post by area51 »

Hi duch,

If you add the mesh's triangle selector to the second bit od code then it should work.

I've quickly done a test, and it works fine, created a door and can't walk throught it, heres the code:

Code: Select all

//! Add DOORS to level
void CGameStateLevel01::addDoors(CGameManager* pManager)
{
	// load in Door
    scene::IAnimatedMesh* doorMesh = 0;
    doorMesh = pManager->getSceneManager()->getMesh("media/portcullis.3DS");
    
    // Create a GameItem object to add to the CgameItemManager
    CGameItem* door = new CGameItem(GAME_ITEM_DOOR); 
    door->setMeshNode(pManager->getSceneManager()->addAnimatedMeshSceneNode(doorMesh));
    if (door->getMeshNode())
    {
        door->getMeshNode()->setMaterialTexture(0, pManager->getDriver()->getTexture("media/health.jpg"));
        door->getMeshNode()->setPosition(pManager->getPathManager()->getWaypointAt(9));
        door->getMeshNode()->setScale(core::vector3df(1,1,1));
        door->getMeshNode()->setMaterialFlag(video::EMF_LIGHTING, false);
        door->getMeshNode()->setID(GAME_ITEM_DOOR); 
        door->setTriggerRegion(70);
        pManager->getItemManager()->AddItem(door);
       	irr::scene::ITriangleSelector* doorSelector = pManager->getSceneManager()->createTriangleSelectorFromBoundingBox(door->getMeshNode()); 
        if(doorSelector) 
		    pManager->getMetaSelector()->addTriangleSelector(doorSelector); 
    }
}
Just added to the end of the other items in the Init() function

Code: Select all

...
	// Add items/effects to level
	addAmmoPickups(pManager);
	addHealthPickups(pManager);
	addKeyPickups(pManager);
	addDoors(pManager);
...
Try using other models, making the model larger, make sure you do it after the level has loaded, remove the 'if(doorSelector)'. in general play around with it, because I cant see anything drasticly wrong with the code.
________
Cheap Glass Bongs
Last edited by area51 on Fri Feb 25, 2011 12:07 am, edited 1 time in total.
Dutch
Posts: 12
Joined: Tue Aug 22, 2006 9:45 pm
Location: UK

doors

Post by Dutch »

Hi area51,

thanks a lot for that. I see where the problem was. this had me up all night last night. (luckily i'm on nightshift :D)

One last thing please: how do i reset the trigger at the end of the animation? I have tried putting a "toggle trigger" on it in gameitemmanager but it works the other way round ie when i get close the anim stops and when i move away the door opens, then when i get inside triggerregion, it stops again:

Code: Select all

//! DOOR Trigger activated
void CGameItemManager::processTriggerDoor(CGameManager* pManager, CGameItem* pItem)
{
	// reset trigger at animation end
		m_bAnimationEnd = false;
        pItem->getMeshNode()->setAnimationEndCallback(this);
	    pItem->getMeshNode()->setAnimationSpeed(30);
        pItem->getMeshNode()->setFrameLoop(0, 220);
		pItem->setLocalInt("door_open", 0); // testing using NWN style softcoded variables
		pItem->toggleTrigger();
}
regards

dutch

ps thanks for your time and patience :!:
pepparoni
Posts: 1
Joined: Mon Aug 28, 2006 9:30 am

penetrating bullets?

Post by pepparoni »

The enemy is shooting throught the walls off the default level, I can play the game in a few sec before i die. :(
how can i fix this?
area51
Posts: 338
Joined: Thu Mar 18, 2004 10:20 pm
Location: UK
Contact:

Post by area51 »

@Dutch. It sounds as if you're almost there. If you can flip the logic somehow. The m_bAnimationEnd flag will be set each time your animation ends, then you can use the pItem->setLocalInt("door_open") to condition the logic in the processDoorTrigger() function.

We will include a door implementation in the next release.

@pepparoni. There are a couple of ways to stop the enemies shooting through walls (I didn't think the problem is so bad though?)

1. Make the nodes in the navGraph closer together.
2. Make the shooting radius shorter
3. Add LOS (line of sight) code in the CGameEnemy::isPathObstructed() function. It's called each time, but only has a //to be implemented comment in it's body.

Option 3 is the prefered solution, this I guess needs to be added for next time also.
________
John Barnard
Last edited by area51 on Fri Feb 25, 2011 12:07 am, edited 1 time in total.
Dutch
Posts: 12
Joined: Tue Aug 22, 2006 9:45 pm
Location: UK

doors

Post by Dutch »

Hi area

thanks for your help. can't get my head around it so i think i will wait until the next release.
Looking forward to it!!!!

regards

dutch
Darkchrono
Posts: 7
Joined: Fri Oct 17, 2003 8:29 pm
Location: If you need me there, I'll be there

Post by Darkchrono »

In the next Release you can see:

A brand new Console easy to use.
O.O Scripting (C++ Syntax like).

Looking for ideas for build in usefull comands for the Console and Scripting API that you like to see in this release
aka Chrono
IrrWizard™ -Developer
Dutch
Posts: 12
Joined: Tue Aug 22, 2006 9:45 pm
Location: UK

Lift

Post by Dutch »

Hi area

fixed my door problem and looking into using a lift in the game.
will i need a physics engine like newton or can i use the collision animators? (i want the game character to walk on a md2 animated mesh which will go up when triggered).

tried a few things but no luck so far. The mesh goes through the character. looked on the forum and the general consencus seems to be that you need a physics engine for that.

regards

Dutch
RapchikProgrammer
Posts: 279
Joined: Fri Dec 24, 2004 6:37 pm

Post by RapchikProgrammer »

If you think of using newton, this example is just made for you! It has sliding doors and lifts and buttons! Its source is included with the demo, you can download it here:

http://s-fonline.com/webhosting/dhenton ... ondemo.php
Dutch
Posts: 12
Joined: Tue Aug 22, 2006 9:45 pm
Location: UK

lifts

Post by Dutch »

thanks rapchick

just wondered if it would be possible with irrlicht alone?

regards

dutch
area51
Posts: 338
Joined: Thu Mar 18, 2004 10:20 pm
Location: UK
Contact:

Post by area51 »

You can do a simple lift without a physics engine. Depending on how you want it to work, you could create a lift trigger the same way as you did with the door. Maybe add the trigger as a swith. Then when triggered, ie near the swith and on the lift, add the camera as a child of the lift and attach a FlystraightAnimator to the lift.

You might need another trigger at the top, or use an animated lift and the callback boolean flag to know when it's at the top or bottom.

I would experiment, try a few things out.
________
List of vehicles
Last edited by area51 on Fri Feb 25, 2011 12:07 am, edited 1 time in total.
area51
Posts: 338
Joined: Thu Mar 18, 2004 10:20 pm
Location: UK
Contact:

Post by area51 »

Site Update:

The existing documentaion has been updated and extended slightly.
It's now Wiki based so anyone can now update, add, modify any of the docs.

If anyone would like to contribute an article, tutorial or just a one line hint/tip, then please feel free.

Any help would be much apreciated, see sig for url.
________
Marijuana vaporizer
Last edited by area51 on Fri Feb 25, 2011 12:09 am, edited 1 time in total.
Post Reply