Saving a players position to an int

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
monkeycracks
Posts: 1029
Joined: Thu Apr 06, 2006 12:45 am
Location: Tennesee, USA
Contact:

Saving a players position to an int

Post by monkeycracks »

Is there a way to do something like

playernode->getPosition();
intxpos = don'tknowhere
intypos = ""
intzpso = ""


Where the x position gets saved to the x int and so on.
esaptonor
Posts: 145
Joined: Sat May 06, 2006 11:59 pm

Post by esaptonor »

do you mean like this?

Code: Select all

core::vector3df pos = playernode->getPosition();

float x = pos.X;
float y = pos.Y;
float z = pos.Z;
monkeycracks
Posts: 1029
Joined: Thu Apr 06, 2006 12:45 am
Location: Tennesee, USA
Contact:

Post by monkeycracks »

That seems to be it, but how would you update the floats so that when you did something like playernode->setPosition(x,z+10,y); it didn't restart you to the original place you spawned the node at.


PS : I'm trying to make a jump function.
esaptonor
Posts: 145
Joined: Sat May 06, 2006 11:59 pm

Post by esaptonor »

im not entirely sure what you mean.
If you mean the z float isn't being updated, well whenever you did do something like playernode->setPosition(x, y+10, z); i would actually do this:

y += 10;

and every game loop, set playernode->setPosition(core::vector3df(x, y, z));
that way it will always be where you set it to be

if thats not what you meant, please explain further.

also, its probably better just to keep the floats inside the vector3df variable. Then when you need to change them, just do pos.Y+=10; and it makes setting them easier as you get to type less: playernode->setPosition(pos);
monkeycracks
Posts: 1029
Joined: Thu Apr 06, 2006 12:45 am
Location: Tennesee, USA
Contact:

Post by monkeycracks »

Code: Select all

         if(event.EventType == EET_KEY_INPUT_EVENT && 
         !event.KeyInput.PressedDown && event.KeyInput.Key == KEY_SPACE)
         {
         playermeshn->setPosition(vector3df(posx,posz+20,posy));
         return true;
         }
In the event receiver...

and in the main loop...

Code: Select all

                      vector3df pos = playermeshn->getPosition();
                      posx = pos.X;
                      posy = pos.Y;
                      posz = pos.Z;
I want the user to be pushed 20 into the air when spacebar is pressed.
esaptonor
Posts: 145
Joined: Sat May 06, 2006 11:59 pm

Post by esaptonor »

your code does put you 20 into the air.
I am still unsure what you are after. I think you mean the variables being saved so you can jump anywhere.
All you need to do for that is in your even receiver, when space is pressed, do the whole thing.

Code: Select all

if(event.EventType == EET_KEY_INPUT_EVENT &&
         !event.KeyInput.PressedDown && event.KeyInput.Key == KEY_SPACE)
{
          vector3df pos = playermeshn->getPosition();
         playermeshn->setPosition(vector3df(pos.X,pos.Y+20,pos.Z));
         return true;
}
and just so you know, i changed posz+20 to pos.Y+20 as the y variable is the vertical one.
monkeycracks
Posts: 1029
Joined: Thu Apr 06, 2006 12:45 am
Location: Tennesee, USA
Contact:

Post by monkeycracks »

Yes, that worked perfectly...
Thanks =)

that solved many problems I was having confusing z with y.
CeeRo
Posts: 11
Joined: Tue Sep 12, 2006 10:17 pm

Post by CeeRo »

Edit: Already answered in another thread
Post Reply