Modulus/maths help; race spawns fails, something wrong ?
#1

Hello guys!

Me and a friend made this little snippet in order to get players spawning in rows and columns.
However, let me explain:

pawn Код:
//startPosition: ("*" is the checkpoint they are headed against)
//  *
//1 2 3
//4 5 6
//7 8 9
//.......

stock GetXYForRacer(&Float:x, &Float:y, Float:a, startPosition)
{
    //x and y should contain the start checkpoint location, a should be the angle of the cars
    new Float:raceSpawnOffsets[2];
    if(((startPosition+1) % 3) == 0)  //I think there is something wrong here, because it will be the same as startposition = 2 on the first and and so on, but how to do the "%" calculations correctly?
    { //Middle
        GetXYAtAngleFromPos(raceSpawnOffsets[0], raceSpawnOffsets[1], a-180.00, 5);
        x += raceSpawnOffsets[0] * (((startPosition-1)/3)+1);
        y += raceSpawnOffsets[1] * (((startPosition-1)/3)+1);
    }
    else
    { //Sides
        GetXYAtAngleFromPos(raceSpawnOffsets[0], raceSpawnOffsets[1], a+90.00, 3);
        if((startPosition % 3) == 0)  
        { //Right side
            x += raceSpawnOffsets[0];
            y += raceSpawnOffsets[1];
        }
        else
        { //Left Side
            x -= raceSpawnOffsets[0];
            y -= raceSpawnOffsets[1];
        }
    }
}
stock GetXYAtAngleFromPos(&Float:x, &Float:y, Float:a, distance)
{
    x += (distance * floatsin(-a, degrees));
    y += (distance * floatcos(-a, degrees));
}


And this is what happens when testing the code above:



Please note that the cars are increasing the offsets further back.
And that there is only 2 rows, where the third vehicle spawn on top of the other. (just placed them side by side)

What should be done here?
And it wouldn't matter if i had two rows only, but how could i do that? It kinda sucks when you work with things you never thought you had use for, so i am open to hear anything to learn.
Reply


Messages In This Thread

Forum Jump:


Users browsing this thread: 1 Guest(s)