Movement HELP

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
lukluk
Posts: 4
Joined: Mon Mar 19, 2007 9:26 pm

Movement HELP

Post by lukluk »

Can someone create for me a sample source for player movement(camera follow player) my englisch ist no good and i cant understand tutorial in this site :/ HELP
dudMaN
Posts: 111
Joined: Fri Mar 02, 2007 6:37 pm

Post by dudMaN »

The camera doesnt 'follow' the player.

Code: Select all

scenemgr->addCameraSceneNodeFPS();
should be enough. this is assuming your scenemanager goes by the name scenemgr.

-dudMan
liger13
Posts: 119
Joined: Tue Jul 18, 2006 4:17 am

Post by liger13 »

that creates a first person camera. did you mean you wanted that or a third person camera, like WoW?
lukluk
Posts: 4
Joined: Mon Mar 19, 2007 9:26 pm

Post by lukluk »

of course i want create third person like WoW camera
JonLT
Posts: 152
Joined: Thu Mar 15, 2007 5:47 pm
Location: Denmark

Post by JonLT »

I suppose you could create a regular ICameraSceneNode, and then setting its target to the player. Camera movement could then be employed with the event receiver (getting mouse movement). This is tricky math though. :wink:
liger13
Posts: 119
Joined: Tue Jul 18, 2006 4:17 am

Post by liger13 »

i think

Code: Select all

 scenemgr->addCameraSceneNodeMaya()
might be able todo something like that, but ive never used it before.
BlindSide
Admin
Posts: 2821
Joined: Thu Dec 08, 2005 9:09 am
Location: NZ!

Post by BlindSide »

No liger13 this will not help. Maya camera is just first person with click and drag. I think this here will help you http://irrlicht.sourceforge.net/phpBB2/ ... hp?t=18074

or

http://irrlicht.sourceforge.net/phpBB2/ ... hp?t=19282
lukluk
Posts: 4
Joined: Mon Mar 19, 2007 9:26 pm

Post by lukluk »

@up
thanks man but i cant compile WoW movements :/ i have error
@topic
where i can put this code :

Code: Select all

#define RUN_SPEED 10 

void Controls::keyDown(int key, bool b) 
{ 
   keysDown[key] = b; 
} 

void Controls::movementUpdate(void) 
{ 
   vector3df moveLoc; 
   vector3df ax1; 
   vector3df ax2; 

   if(keysDown[KEY_KEY_W] && keysDown[KEY_KEY_D]) 
   { 
      ax1 = vector3df(0, 0, 1 * RUN_SPEED); 
      vEngine->cam->getAbsoluteTransformation().rotateVect(ax1); 
      ax2 = vector3df(1 * RUN_SPEED, 0, 0); 
      vEngine->cam->getAbsoluteTransformation().rotateVect(ax2); 
      moveLoc = vEngine->cam->getAbsolutePosition() + ax1 + ax2; 
      moveLoc.Y = vEngine->cam->getAbsolutePosition().Y; 
   } 
   if(keysDown[KEY_KEY_W] && keysDown[KEY_KEY_A]) 
   { 
      ax1 = vector3df(0, 0, 1 * RUN_SPEED); 
      vEngine->cam->getAbsoluteTransformation().rotateVect(ax1); 
      ax2 = vector3df(1 * RUN_SPEED, 0, 0); 
      vEngine->cam->getAbsoluteTransformation().rotateVect(ax2); 
      moveLoc = vEngine->cam->getAbsolutePosition() + ax1 - ax2; 
      moveLoc.Y = vEngine->cam->getAbsolutePosition().Y; 
   } 
   if(keysDown[KEY_KEY_S] && keysDown[KEY_KEY_D]) 
   { 
      ax1 = vector3df(0, 0, 1 * RUN_SPEED); 
      vEngine->cam->getAbsoluteTransformation().rotateVect(ax1); 
      ax2 = vector3df(1 * RUN_SPEED, 0, 0); 
      vEngine->cam->getAbsoluteTransformation().rotateVect(ax2); 
      moveLoc = vEngine->cam->getAbsolutePosition() - ax1 + ax2; 
      moveLoc.Y = vEngine->cam->getAbsolutePosition().Y; 
   } 
   if(keysDown[KEY_KEY_S] && keysDown[KEY_KEY_A]) 
   { 
      ax1 = vector3df(0, 0, 1 * RUN_SPEED); 
      vEngine->cam->getAbsoluteTransformation().rotateVect(ax1); 
      ax2 = vector3df(1 * RUN_SPEED, 0, 0); 
      vEngine->cam->getAbsoluteTransformation().rotateVect(ax2); 
      moveLoc = vEngine->cam->getAbsolutePosition() - ax1 - ax2; 
      moveLoc.Y = vEngine->cam->getAbsolutePosition().Y; 
   } 
   if(keysDown[KEY_KEY_W] && !keysDown[KEY_KEY_A] && !keysDown[KEY_KEY_D] && !keysDown[KEY_KEY_S]) 
   { 
      ax1 = vector3df(0, 0, 1 * RUN_SPEED); 
      vEngine->cam->getAbsoluteTransformation().rotateVect(ax1); 
      moveLoc += vEngine->cam->getAbsolutePosition() + ax1; 
      moveLoc.Y = vEngine->cam->getAbsolutePosition().Y; 
   } 
   if(keysDown[KEY_KEY_S] && !keysDown[KEY_KEY_A] && !keysDown[KEY_KEY_D] && !keysDown[KEY_KEY_W]) 
   { 
      ax1 = vector3df(0, 0, 1 * RUN_SPEED); 
      vEngine->cam->getAbsoluteTransformation().rotateVect(ax1); 
      moveLoc += vEngine->cam->getAbsolutePosition() - ax1; 
      moveLoc.Y = vEngine->cam->getAbsolutePosition().Y; 
   } 
   if(keysDown[KEY_KEY_D] && !keysDown[KEY_KEY_A] && !keysDown[KEY_KEY_S] && !keysDown[KEY_KEY_W]) 
   { 
      ax1 = vector3df(1 * RUN_SPEED, 0, 0); 
      vEngine->cam->getAbsoluteTransformation().rotateVect(ax1); 
      moveLoc += vEngine->cam->getAbsolutePosition() + ax1; 
      moveLoc.Y = vEngine->cam->getAbsolutePosition().Y; 
   } 
   if(keysDown[KEY_KEY_A] && !keysDown[KEY_KEY_S] && !keysDown[KEY_KEY_D] && !keysDown[KEY_KEY_W]) 
   { 
      ax1 = vector3df(1 * RUN_SPEED, 0, 0); 
      vEngine->cam->getAbsoluteTransformation().rotateVect(ax1); 
      moveLoc += vEngine->cam->getAbsolutePosition() - ax1; 
      moveLoc.Y = vEngine->cam->getAbsolutePosition().Y; 
   } 
   if(!keysDown[KEY_KEY_W] && !keysDown[KEY_KEY_S] && !keysDown[KEY_KEY_A] && !keysDown[KEY_KEY_D]) 
   { 
      moveLoc = vEngine->cam->getAbsolutePosition(); 
   } 

   vEngine->cam->setPosition(moveLoc); 
} 

bool Controls::OnEvent(SEvent event) 
{ 
   if(event.EventType == EET_KEY_INPUT_EVENT) 
   { 
      //Keyboard events here 
      if(event.KeyInput.PressedDown) 
      { 
         keyDown(event.KeyInput.Key, true); 
         movementUpdate(); 
      } 
      else 
      { 
         for(int i = 0; i < 256; i++) 
            keyDown(i, false); 
      } 
   } 

   return true; 
}
in my code :

Code: Select all

#include <stdio.h>
#include <wchar.h>
#include <irrlicht.h>
#pragma comment(lib, "Irrlicht.lib")

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

int main()
{
		
createDevice(EDT_SOFTWARE, dimension2d<s32>(600, 600), 16,			
			 false, false, false, 0);

device->setWindowCaption(L"Hello World! - Irrlicht Engine Demo");

IVideoDriver* driver = device->getVideoDriver();
ISceneManager* smgr = device->getSceneManager();
IGUIEnvironment* guienv = device->getGUIEnvironment(); 

guienv->addStaticText(L"Hello World! This is the Irrlicht Software engine!",
					  rect<int>(10,30,200,44), true);

IAnimatedMesh* cam = smgr->getMesh("media/tris.md2");
IAnimatedMeshSceneNode* node = smgr->addAnimatedMeshSceneNode( cam );

if (node)
{	
	node->setMaterialFlag(EMF_LIGHTING, false);	
	node->setFrameLoop(0, 310);		
	node->setMaterialTexture( 0, driver->getTexture("media/alien.pcx") );
} 

smgr->addCameraSceneNode(0, vector3df(0,30,-40), vector3df(0,5,0));

while(device->run())
{ 
	driver->beginScene(true, true, SColor(255,100,101,140));
	smgr->drawAll();
	guienv->drawAll();	driver->endScene();
}

	device->drop(); return 0;
}
liger13
Posts: 119
Joined: Tue Jul 18, 2006 4:17 am

Post by liger13 »

thats part of an eventReciever class i think. just add it to the device with

Code: Select all

device->setEventReceiver();
Post Reply