[Math] Angle and more
#1

Hello.
I'm probably too stupid to know how can I calculate a coordinates with the player's facing angle.
I mean, I wante to create 3-4 objects and elevate it every update. I'll use a loop and get the right coordinates. The problem is I don't know where I can modify it for the player's facing angle. (My english suck so much, sorry).
PHP код:
+= size floatcos(idegrees); 
Where size is the distance between first & second object.
Reply
#2

http://forum.sa-mp.com/showpost.php?...35&postcount=3

Z would just have to be set +n.n.
Reply
#3

Quote:
Originally Posted by SickAttack
Посмотреть сообщение
I tried to do : + ang but it's increased the distance between 2 objects ^.^'
Reply
#4

That function already gives you the position in front of the player according to the player's angle and the specified distance from the player's position. All you need to do is increase the z axis.
Reply
#5

The "offset" variable from this code seems to be pointless because the "a" variable gets assigned to the angle of player or vehicle.
NOTE : This function is simply named "GetPosInfrontOfPlayer". It creates a slanting line with "fDistance" separation in 3D.
pawn Код:
stock GetPosInfrontOfPlayer(playerid, Float:fDistance, &Float:fX, &Float:fY, &Float:fZ) {

    new
        Float:fAngle;
    if(fX == 0.0 && fY == 0.0 && fZ == 0.0) //IF they're at origin, player pos is taken. Otherwise, it will just modify it's position to the position infront.
            GetPlayerPos(playerid, fX, fY, fZ);

    if(IsPlayerInAnyVehicle(playerid))
        GetVehicleZAngle(GetPlayerVehicleID(playerid), fAngle);
    else
        GetPlayerFacingAngle(playerid, fAngle);

    fX += fDistance * floatsin(-fAngle, degrees);
    fY += fDistance * floatcos(-fAngle, degrees);
    fZ += fDistance;
    return 1;
}

//test command.
public OnPlayerCommandText(playerid, cmdtext[]) {

    if(!strcmp(cmdtext, "/placeobjects", true)) {
   
        new
            Float:fX,
            Float:fY,
            Float:fZ
        ;
        //To be used with this function, they must be 0.0 at first. Since they're
        //already 0.0, I do not have to do:
        //fX = fY = fZ = 0.0;
        for(new i = 0; i< 5; i++) {
       
            GetPosInfrontOfPlayer(playerid, 1.0, fX, fY, fZ);
            CreateObject(2114, fX, fY, fZ, 0.0, 0.0, 0.0, 200.0);
        }
        return 1;
    }
    return 0;
}
Reply
#6

I'm not trying to get one pos, but in a loop.
PHP код:
    for(new i<= 360i++)
    {
        
z+size*floatcos(i,degrees); //+ floatcos(-ang,degrees);
          
y+size*floatsin(i,degrees); //+ floatsin(-ang,degrees); 
Reply
#7

The function I wrote can be used in loop, which is why it checks if fX == fY == fZ == 0.0. Test the example for yourself. You mentioned on your first post that you want to elevate 3-4 objects. Well, are you talking about doing something like this? (It's what the command I gave you does):
Click for picture - it's quite large.
Reply
#8

I'm trying to make a circle. x)
This working good except, the circle is oriented to a fixed angle (north on your minimap).
Reply
#9

https://sampforum.blast.hk/showthread.php?tid=38965&page=425
Reply
#10

Why are u naming ur variable Z? it should be X and Y ? isnt it? for X just add distance*floatsin (-angle, degrees);
for y add distance*floatcos(-angle,degrees)

thats it. its that simple
Reply


Forum Jump:


Users browsing this thread: 2 Guest(s)