weird but easy[solved by me lol]

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
omar shaaban
Posts: 616
Joined: Wed Nov 01, 2006 6:26 pm
Location: Cairo,Egypt
Contact:

weird but easy[solved by me lol]

Post by omar shaaban »

EDIT: the problem was with the numbers so here is my new code now:

Code: Select all

void move(unit &a)
{
int speed=tilesize;

poss=a.mesha->getPosition();
 if(a.destx*tilesize<int(poss.X) && (mymap[a.chary][a.charx-1])!=2 )
{
poss.X-=speed*elapsed;
  a.statenext=3;
   a.mesha->setRotation(core::vector3df(0,-90,0));
}

 if(a.destx*tilesize>int(poss.X) && (mymap[a.chary][a.charx+1])!=2 )
{
    poss.X+=speed*elapsed;
  a.statenext=3;
   a.mesha->setRotation(core::vector3df(0,90,0));

}


if(a.desty*tilesize<int(poss.Z)  && (mymap[a.chary-1][a.charx])!=2 )
{
    poss.Z-=speed*elapsed;
     a.mesha->setRotation(core::vector3df(0,180,0));


}

 if(a.desty*tilesize>int(poss.Z) && (mymap[a.chary+1][a.charx])!=2 )
{
    poss.Z+=speed*elapsed;
     a.mesha->setRotation(core::vector3df(0,0,0));
      a.statenext=3;
}





a.mesha->setPosition(poss);
    }
////////////////////////////////////////////////////////////////////////////////////
well my problem is in this code:
code no 1

Code: Select all

if(a.destx<(poss.X/tilesize) && (mymap[a.chary][a.charx-1])!=2 )
{
poss.X-=speed*elapsed;
  a.statenext=3;
   a.mesha->setRotation(core::vector3df(0,-90,0));
}
code no 2

Code: Select all

 if(a.destx>int((poss.X/tilesize)) && (mymap[a.chary][a.charx+1])!=2 )
{
    poss.X+=speed*elapsed;
  a.statenext=3;
   a.mesha->setRotation(core::vector3df(0,90,0));

}
code no 3

Code: Select all

if(a.desty<(poss.Z/tilesize)  && (mymap[a.chary-1][a.charx])!=2 )
{
    poss.Z-=speed*elapsed;
     a.mesha->setRotation(core::vector3df(0,180,0));


}

code no 4

Code: Select all

 if(a.desty>int((poss.Z/tilesize)) && (mymap[a.chary+1][a.charx])!=2 )
{
    poss.Z+=speed*elapsed;
     a.mesha->setRotation(core::vector3df(0,0,0));
      a.statenext=3;
}

a.mesha is a cube so... when i set the destx to number higher than charx the mesh moves to the right and when i set the desty to a number higher than chary it goes up but the problem comes when i decrease i mean when i go left or down even if i dont want to!!!! i dont know why but it seams that the code no 3 when i put it the last one the comp run it also desty=chary!!!! i don't know why and that make also problems with code no 1 if i put it under code no2 but if i arranged them like what i did above it works good!!? but why it runs the code although it is not supposed to run (> and < are false) and also if i put int to the values in code no 3 it just dont work and make errors bec the int thingy (i mean that int doesn't have 1.6 or 1.5 but 1 or 2) so any explanation!!?
Last edited by omar shaaban on Wed Aug 08, 2007 5:48 am, edited 2 times in total.
omar shaaban
Posts: 616
Joined: Wed Nov 01, 2006 6:26 pm
Location: Cairo,Egypt
Contact:

Post by omar shaaban »

edit:and also another thing if i put else between codeno1 and codeno2 and another else between code no3 and no4 the model keeps shaking because
the model.z goes for example 80 then 81 then 80 then 81 and in x it goes 76 then77 .....etc!!!!

opps the problem is still here with the rotations since the code runs the last one even if shouldnt i mean runs code no 4 so if my mesh is moving down and stops the rotation goes back to 0,0,0 but it suppose to stay at 0,90,0 as the last code played was code no3 !!!ahhh plz help in this plz plz


and also when the mesh only moves to the right it doesnt rotate bec the code no4 affects the rotation!!!? but the code no4 shouldnt suppose to work!! but it changes the rotaion to 0,0,0 and the mesh when moving left with desty=chary it should face right not 0,0,0 ahhh i wthink i am goona be crazy!!![/b]
mhack
Posts: 38
Joined: Sun Apr 01, 2007 2:13 am
Location: Montana, USA

Post by mhack »

This may not help you with your immediate problem, but you might find some interesting reading here:

http://www.gamesfromwithin.com/articles ... pment.html
omar shaaban
Posts: 616
Joined: Wed Nov 01, 2006 6:26 pm
Location: Cairo,Egypt
Contact:

Post by omar shaaban »

mhack wrote:This may not help you with your immediate problem, but you might find some interesting reading here:

http://www.gamesfromwithin.com/articles ... pment.html
so how this will help my problem? do u specify a certain article to read or to read the whole thing
mhack
Posts: 38
Joined: Sun Apr 01, 2007 2:13 am
Location: Montana, USA

Post by mhack »

The general way it can help you is by suggesting how to create simple, small tests that can make it much easier to catch your programming mistakes. In addition (as mentioned in the first article) it makes the interesting point that a test-driven-development style can actually influence your game design to be naturally more modular, which also makes testing and finding bugs a lot easier.

I would recommend reading all of the articles, beginning with
Stepping Through the Looking Glass: Test-Driven Game Development (Part 1)
omar shaaban
Posts: 616
Joined: Wed Nov 01, 2006 6:26 pm
Location: Cairo,Egypt
Contact:

Post by omar shaaban »

thanks i will look into it
Post Reply