project problem...hlp needed

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
R@!D3N
Posts: 8
Joined: Thu Apr 29, 2010 4:59 pm

project problem...hlp needed

Post by R@!D3N »

hey guys i have a problem with my code ... im making a 3rd person game
and im having some problems...

1. on key press my animated character doesnt play its animation
like when i press w its supposed to play the walking animation but it doesnt play the animation...

2. another problem is that i want to adjust the camera with the character node.. like when i press w the key the node moves and i want the camera to move with it, (behind the character), u no...like how the camera is in 3rd person games...

3. another problem is the cutscenes... can u guys give me any help on cutscenes.???

the code on this link isnt working...
http://irrlicht.sourceforge.net/phpBB2/ ... c&start=45

here is my code... any quick help would be gr8... its for a project im doing and the due date is coming up .... quick help needed...

Code: Select all

#include<irrlicht.h>


#pragma comment(lib, "Irrlicht.lib")

bool keys[irr::KEY_KEY_CODES_COUNT];

using namespace irr;
using namespace core;
using namespace scene;
using namespace video;
using namespace gui;

class MyEventReceiver : public IEventReceiver { 
 public: 
 virtual bool OnEvent(const SEvent& event) {
  if(event.EventType == irr::EET_KEY_INPUT_EVENT){ 
   keys[event.KeyInput.Key] = event.KeyInput.PressedDown; 
   return false; 
  } 
   return false; 
  } 
}; 



int main()
{

IrrlichtDevice*device = createDevice(EDT_DIRECT3D9);
									
core::dimension2d<s32>(1280,800);
IVideoDriver* video = device->getVideoDriver();

ISceneManager*smgr = device->getSceneManager();
//device->getFileSystem("C:/Users/X360/shovq2dm1_cpm.pk3");

//scene::IAnimatedMesh* mash = smgr->getMesh("shovq2dm1_cpm.bsp");
//scene::ISceneNode* nade = 0;
//if (mash)
//	nade = smgr->addOctreeSceneNode(mash->>getMesh(0), 0, -1, 1024);
scene::IAnimatedMesh * gamemap = smgr->getMesh("C:/Users/X360/GameMap.3DS");
//smgr->addAnimatedMeshSceneNode(smgr->getMesh("C:/Users/X360/chk111.3DS"));
//smgr->loadScene("C:/Users/X360/chk223.irr");	

scene::IAnimatedMeshSceneNode * mapnode = smgr->addAnimatedMeshSceneNode(gamemap);
	if (mapnode)
	{
		mapnode->setMaterialFlag(video::EMF_LIGHTING,false);
	}
	////////////////////////////////// PART OF COLLISION DETECTION /////////////////////////////////////////
	scene::ISceneNode * mnode = 0;

	if(gamemap)
		mnode = smgr ->addOctTreeSceneNode(gamemap ->getMesh(0));

	
	scene::ITriangleSelector * selector = 0;
	if(mnode)
	{
		selector = smgr->createOctreeTriangleSelector(gamemap ->getMesh(0),mnode, 128);
		mnode ->setTriangleSelector(selector);
	}

	////////////////////////////////////////////////////////////////////////////////////////////////////////

IAnimatedMesh* mesh = smgr->getMesh("D:/Project/OOP Project(Main)/Tutes & models/ninja/ninja.b3d");
	
	if (!mesh)
	{
		device->drop();
		return 1;
	}
	IAnimatedMeshSceneNode* node = smgr->addAnimatedMeshSceneNode( mesh );
	if (node)
	{
		node->setMaterialFlag(video::EMF_LIGHTING,false);
	}
node->setMaterialTexture( 0, video->getTexture("D:/Project/OOP Project(Main)/Tutes & models/ninja/nskinwh.jpg") );

//smgr->loadScene("C:/Users/X360/asd.irr");

ISceneNode * Skybox = smgr->addSkyBoxSceneNode(video->getTexture("D:/Project/Models/sky14/Sky1/Side6.png"),video->getTexture("D:/Project/Models/sky14/Sky1/Side1.png"),video->getTexture("D:/Project/Models/sky14/Sky1/Side4.png"),video->getTexture("D:/Project/Models/sky14/Sky1/Side3.png"),video->getTexture("D:/Project/Models/sky14/Sky1/Side5.png"),video->getTexture("D:/Project/Models/sky14/Sky1/Side2.png"));	


MyEventReceiver rv; 
device->setEventReceiver(&rv);

for(int x=0;x<irr::KEY_KEY_CODES_COUNT;x++)keys[x]=false;


node->setPosition(vector3df(0,35,5));
node->setScale(vector3df(25,25,25));
///////////////////////////////////////////////////////////PART OF COLLISION DETECTION///////////////////////////////////////////

scene::ISceneNodeAnimator *anim = smgr ->createCollisionResponseAnimator(selector, node, vector3df(25,25,25),
																		 vector3df(0,-3,0), vector3df(0,50,0));
selector ->drop();
node ->addAnimator(anim);
anim ->drop();

/////////////////////

ICameraSceneNode* cam = smgr->addCameraSceneNodeFPS();
cam->setTarget(node->getPosition()); 
 
while (device->run() && device)
{
	core::vector3df nodePosition = node->getPosition();

if(keys[KEY_KEY_S]) 
	{

		

		node->setAnimationSpeed(200);
		node->setLoopMode(true);
		node->setFrameLoop(1,14);
		node->setPosition(node->getPosition()+vector3df(0,0,30));
		node->setRotation(core::vector3df(0.0f , 180.0f , 0.0f));
		
		//node->setAnimationEndCallback(0);
		cam->setTarget(node->getPosition()+vector3df(0,0,3));
		
}
else
{
	node->setFrameLoop(184,205);
	node->setLoopMode(true);
	node->setAnimationSpeed(25);
}
if(keys[KEY_KEY_A]) 
	{
		node->setAnimationSpeed(200);
		node->setLoopMode(true);
		node->setFrameLoop(1,14);
		node->setPosition(node->getPosition()-vector3df(30,0,0));
		node->setMD2Animation(scene::EMAT_RUN);
		node->setRotation(core::vector3df(0.0f , 0.0f , 0.0f));
		cam->setTarget(node->getPosition());
	}

if(keys[KEY_KEY_D]) 
	{
		node->setCurrentFrame(1);
		node->setAnimationSpeed(200);
		node->setLoopMode(true);
		node->setFrameLoop(1,14);
		node->setPosition(node->getPosition()+vector3df(30,0,0));
		node->updateAbsolutePosition();
		node->setRotation(core::vector3df(0.0f , 90.0f , 0.0f));
		cam->setTarget(node->getPosition());
	}

if(keys[KEY_KEY_W]) 
	{
		
		node->setAnimationSpeed(200);
		node->setLoopMode(true);
		node->setFrameLoop(1,14);
		node->setPosition(node->getPosition()-vector3df(0,0,30));
		node->setRotation(core::vector3df(0.0f , 180.0f , 0.0f));
		cam->setTarget(node->getPosition()+vector3df(4,0,0));
	}

if(keys[KEY_KEY_Z])
	{
		node->setFrameLoop(45,59);
		cam->setTarget(node->getPosition());
	}


	video->beginScene(true,true, video::SColor(245,0,1,255));
	smgr->drawAll();
	video->endScene();
}
}
thanks in advance...
Tr3nT
Posts: 65
Joined: Thu Nov 29, 2007 5:19 pm

Post by Tr3nT »

uhm....i'm quite new in irrlicht, maybe i'm wrong but the assigment for the animation is inside the loop, then in any loop if a key is pressed the animation is set again....
you should need 2 vabiables that store the animation you are doing and the key that is pressed/than that you need)..for example in the event receiver for each key pressed i save a value in a variable (for example variable CurrentAction is: 0=idle,1=moving,2=shoot....etc)
than there is another variable OldAction(set to 0 at the beginning)
than in the loop u compare the old action with the new like this

Code: Select all


while(device->run())
{
if(CurrentAction==0&&OldAction!=CurrentAction)
    {
     //set the idle animation
     OldAction=CurrentAction;
     }

 if(CurrentAction==1&&OldAction!=CurrentAction)
    {
     //set the run animation
     OldAction=CurrentAction;
     }
........
}
then if u have the same animation requasted in 2 loops u don't change the aniation
to set the vamera you shoud do something like this in the loop

Code: Select all

*/ops..i've done an error here...:D because u need also the rotation of the node in order to make the rotation of the camera around the character using cos and sin function...u need to add the math include file to make it...
int dist = 30; //the distance of the camera
int hei = 30;//the height of the camera
vector3df rot=char->getRotation();
//the 57.1 change the value from radiants to grades
cam->setPosition(node->getPosition()+vector3df(sin(rot.X*57.1),y,cos(rot.Z*57.1));
cam->settarget(node->getPosition());
where x,y and z are variables to set your camera in a relative position with you character node....
and the target is necessary to make the camera directed to the character node...

i hope u understand my english....:D
and i hope this works:D
Post Reply