Trigonometric functions- get angle from player to point. -
robhol - 03.03.2008
I just wondered if anybody might have this function ready- I'm no big wizz at trigonometry, and we haven't learned about it in school.
My problem is this; There are two players on a server (A and B). A enters a command that will tell him B's location, and how many degrees to turn to face him. How to make this command? I know it should be possible, it's just... kinda out of my league at the moment.
Re: Trigonometric functions- get angle from player to point. -
[LDT]LuxurY - 03.03.2008
oh, something with sin and cos. but I haven't time to think about it
Re: Trigonometric functions- get angle from player to point. -
robhol - 03.03.2008
Quote:
Originally Posted by [LDT
LuxurY ]
oh, something with sin and cos. but I haven't time to think about it
|
Then why the hell do you post...
I know it's Sin(-e) and Cos(-ine), I already said so in my topic title. There's probably a Tan(-gent) hiding somewhere in there too. I just have no fricking clue how to use them.
Re: Trigonometric functions- get angle from player to point. -
Antironix - 03.03.2008
You have a triangle like this
a b
----
| /
|/
c
To calculate a-c you need to know b-c and use co-sinus.
Well, that's a little, i am tired right now, i will give you what cos, sin and tan does.
Sin = Looking from the corner b, oposide(a-c) : diagonal side(b-c)
Cos = Opposide : diagonal side
Tan = Opposide : the line connected with the start corner. Like if you have the "start" corner c, the "line" is a-c
diagonal side is the side what doesn't have a 90 degree corner.
I know, it's a little bit messy, but i hope you understand some more.
Re: Trigonometric functions- get angle from player to point. -
robhol - 03.03.2008
Vaguely- but it's not like I can read that and suddenly make the whole function, if you get my meaning... Thanks for the help though.
Has anybody got that formula? :P
Re: Trigonometric functions- get angle from player to point. -
robhol - 16.03.2008
I still need this and an answer would be very nice.. anyone?
Re: Trigonometric functions- get angle from player to point. -
Puffmac - 16.03.2008
Quote:
Originally Posted by robhol
I still need this and an answer would be very nice.. anyone?
|
OK, wth is trignonometry? Lol, me forget. Mabey something like this, or mabey it has fuck all to do with it
:
pawn Код:
if(!strcmp(cmdtext, "/ppos", true)) {
new id; // this is the variable for the second person
new Float:idang, Float:playeridang;
GetPlayerFacingAngle(playerid,playeridang);
GetPlayerFacingAngle(id,idang);
new diff;
if(playeridang > idang) diff = playeridang-idang
else diff = idang-playerid;
return diff;
format(str,sizeof(str),"Turn %d dgrees",diff);
SendClientMessage(playerid,0xFFFF00AA,str);
return 1;
}
Re: Trigonometric functions- get angle from player to point. -
robhol - 17.03.2008
Sorry, Puff, but that
has pretty much fuck all to do with it
I need to get a command that makes the player face a point, given X and Y.
Re: Trigonometric functions- get angle from player to point. -
yom - 17.03.2008
I tried doing something like that long time ago, failed. But now there is atan (and atan2), it will probably be easier. I will maybe retry, as i may need it too.
Re: Trigonometric functions- get angle from player to point. -
MidoBan - 17.03.2008
I dont know if i'm correct, but i'm not sure that u need those cos and sin functions for this.
I built a pet system and when the pet attacks, it chases the player and always facing him.
I just took the target player's angle subtracted it form 180 (180-the target's angle). Then i applied the outcome angle on the pet.
yom, u replied to my question on my pets topic with the 180 degrees thing..
So y won't it work on this script? just subtract the outcome of the 180 degrees thing from the player's facing angle, and thats how much he need to turn... no?
Re: Trigonometric functions- get angle from player to point. -
ғαιιοцт - 16.02.2009
Code:
stock SetPlayerLookAt(playerid, Float:x, Float:y)
{
new Float:Px, Float:Py, Float: Pa;
GetPlayerPos(playerid, Px, Py, Pa);
Pa = floatabs(atan((y-Py)/(x-Px)));
if (x <= Px && y >= Py) Pa = floatsub(180, Pa);
else if (x < Px && y < Py) Pa = floatadd(Pa, 180);
else if (x >= Px && y <= Py) Pa = floatsub(360.0, Pa);
Pa = floatsub(Pa, 90.0);
if (Pa >= 360.0) Pa = floatsub(Pa, 360.0);
SetPlayerFacingAngle(playerid, Pa);
}
it works
http://forum.sa-mp.com/index.php?topic=89955.msg579674#msg579674