Grandad
05-10-11, 10:27 AM
I've been using the 'standard' coding for PlayerWalkTo(posx) but I've had trouble with the player spinning on the spot on one occasion and had to amend the x position to something that was not a multiple of four pixels. Jamie suggested that this could happen if the player wasn't in the exact x co-ordinate. Unfortunately a gamer has experienced the same problem in a part of the game that didn't play up when I was testing it. I've amended this coding to separate right and left walking and setting the player in the x position designated after walking. It seems to work, but I'd be grateful if someone could confirm that this will solve the problem in all cases. Obviously the 'posx' position is always set to a multiple of four pixels.
func PlayerWalkTo( posx )
{
while(true)
{
ClearKeys();
x = PlayerGet(P_X);
if(x < posx)
SetKey(KEY_RIGHT,1);
else
if(x > posx)
SetKey(KEY_LEFT,1);
else
return;
stop;
}
}
amended code (walking left is the opposite and posx always set at multiples of 4 pixels)
func PlayerWalkRight(posx)
{
while(true)
{
ClearKeys();
x = PlayerGet(P_X);
if(x < posx)
SetKey(KEY_RIGHT, 1);
if (x > =posx)
return;
stop;
}
}
func PlayerWalkTo( posx )
{
while(true)
{
ClearKeys();
x = PlayerGet(P_X);
if(x < posx)
SetKey(KEY_RIGHT,1);
else
if(x > posx)
SetKey(KEY_LEFT,1);
else
return;
stop;
}
}
amended code (walking left is the opposite and posx always set at multiples of 4 pixels)
func PlayerWalkRight(posx)
{
while(true)
{
ClearKeys();
x = PlayerGet(P_X);
if(x < posx)
SetKey(KEY_RIGHT, 1);
if (x > =posx)
return;
stop;
}
}