stilianos
01-15-2011, 07:43 AM
I'm having a little trouble coding in multi-directional shooting in my game:
Basically I have:
if (left)
{
player.x -= player.agility;
boltDir = 270;
}
if (down)
{
player.y += player.agility;
boltDir = 180;
}
if (right)
{
player.x += player.agility;
boltDir = 90;
}
if (up)
{
player.y -= player.agility;
boltDir = 0;
}
if (up && right)
{
boltDir = 45;
}
if (up && left)
{
boltDir = 315;
}
if (down && right)
{
boltDir = 135;
}
if (down && left)
{
boltDir = 225;
}
boltDir is the direction of the fired object, the above code works great, the only problem is 50% of the time if you are trying to do a diagonal shot for example up-left, it will get stuck and go left or up not diagonally.
Anyone know how to improve this?
Thanks
Basically I have:
if (left)
{
player.x -= player.agility;
boltDir = 270;
}
if (down)
{
player.y += player.agility;
boltDir = 180;
}
if (right)
{
player.x += player.agility;
boltDir = 90;
}
if (up)
{
player.y -= player.agility;
boltDir = 0;
}
if (up && right)
{
boltDir = 45;
}
if (up && left)
{
boltDir = 315;
}
if (down && right)
{
boltDir = 135;
}
if (down && left)
{
boltDir = 225;
}
boltDir is the direction of the fired object, the above code works great, the only problem is 50% of the time if you are trying to do a diagonal shot for example up-left, it will get stuck and go left or up not diagonally.
Anyone know how to improve this?
Thanks