Calculate angle between two players and get heading? -
denNorske - 29.10.2014
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
Re: Calculate angle between two players and get heading? -
BroZeus - 29.10.2014
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));
}
Re: Calculate angle between two players and get heading? -
Threshold - 29.10.2014
What exactly do you mean by 'heading'. You want the direction they are in the aspect of the player?
Re: Calculate angle between two players and get heading? -
denNorske - 29.10.2014
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)