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: 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: 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: 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;
}
Code: Select all