Calculate angle between two players and get heading?
#1

Hello again!


TITLE CORRECTION: Get Angle from player A to player B

Working on some features, i got this awesome idea to my mind. It's based on CnR and hunting, but i can't say too much about it until i get it done; but i would need some help achieving this.

Based on Vectors, (i've had physics for two years) i know one can simply calculate the angle between two points and then get the exact heading towards the second point. (https://sampforum.blast.hk/showthread.php?tid=491604)

My english ain't the best, so i'm struggling a bit to find the right functions to use for my code.

Lets say the two points are dynamic, such as two players, i get the position from them and the script calculates the heading in degrees in x,y , not necessarily the elevation. How would the function look? Are there any stock functions to use, or do i need to calculate the magnitude and all that myself?

I would like to know what to do exactly, it feels different in sa-mp even tho it shouldn't be :P

Thanks
Reply
#2

Not sure if this is what you are looking for..
pawn Код:
stock GetXYInFrontOfPlayer(playerid, &Float:x, &Float:y, Float:distance)
{
    // Created by ******

    new Float:a;

    GetPlayerPos(playerid, x, y, a);
    GetPlayerFacingAngle(playerid, a);

    if (GetPlayerVehicleID(playerid)) {
        GetVehicleZAngle(GetPlayerVehicleID(playerid), a);
    }

    x += (distance * floatsin(-a, degrees));
    y += (distance * floatcos(-a, degrees));
}
Reply
#3

What exactly do you mean by 'heading'. You want the direction they are in the aspect of the player?
Reply
#4

Well, sorry about my bad definitions above, yea I was looking for something like the angle of the player (a),



Basically what I was trying to say

I need the angle in order to for example change the heading of an object according to player B's position.


EDIT 1:

Quote:
Originally Posted by BroZeus
Посмотреть сообщение
Not sure if this is what you are looking for..
pawn Код:
stock GetXYInFrontOfPlayer(playerid, &Float:x, &Float:y, Float:distance)
{
    // Created by ******

    new Float:a;

    GetPlayerPos(playerid, x, y, a);
    GetPlayerFacingAngle(playerid, a);

    if (GetPlayerVehicleID(playerid)) {
        GetVehicleZAngle(GetPlayerVehicleID(playerid), a);
    }

    x += (distance * floatsin(-a, degrees));
    y += (distance * floatcos(-a, degrees));
}
This code, ain't that just figuring out the x's & y's in the players heading direction? or did i misunderstand that aswell?
Sorry, i might need to read some maths here!


Edit 2:

https://www.youtube.com/watch?v=QsVh-nFg-Vk > That is basically showing an object rotating itself towards the player. How to get the heading? I am interested in knowing how you can get the heading towards a player (same concept)
Reply


Forum Jump:


Users browsing this thread: 2 Guest(s)