Page 1 of 1

Movement HELP

Posted: Mon Mar 19, 2007 9:29 pm
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

Posted: Tue Mar 20, 2007 2:07 am
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

Posted: Tue Mar 20, 2007 3:04 am
by liger13
that creates a first person camera. did you mean you wanted that or a third person camera, like WoW?

Posted: Tue Mar 20, 2007 6:44 pm
by lukluk
of course i want create third person like WoW camera

Posted: Wed Mar 21, 2007 5:26 pm
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:

Posted: Wed Mar 21, 2007 6:14 pm
by liger13
i think

Code: Select all

 scenemgr->addCameraSceneNodeMaya()
might be able todo something like that, but ive never used it before.

Posted: Wed Mar 21, 2007 6:29 pm
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

Posted: Wed Mar 21, 2007 9:08 pm
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;
}

Posted: Thu Mar 22, 2007 4:44 am
by liger13
thats part of an eventReciever class i think. just add it to the device with

Code: Select all

device->setEventReceiver();