SA-MP Forums Archive
Calculus... bleck - Printable Version

+- SA-MP Forums Archive (https://sampforum.blast.hk)
+-- Forum: SA-MP Scripting and Plugins (https://sampforum.blast.hk/forumdisplay.php?fid=8)
+--- Forum: Scripting Help (https://sampforum.blast.hk/forumdisplay.php?fid=12)
+---- Forum: Help Archive (https://sampforum.blast.hk/forumdisplay.php?fid=89)
+---- Thread: Calculus... bleck (/showthread.php?tid=138759)



Calculus... bleck - dracar - 03.04.2010

I need to find the point behind a car, no matter what direction its facing. Haven't taken a calc class yet, I think that's what I need here. I believe this is the code I need, but i don't know anything at all about sine/cosine
Код:
X += (5.0*floatsin(-(A-45.0), degrees));
Y += (5.0*floatcos(-(A-45.0), degrees));
Id like an explanation too so I can do it myself in the future.

Thanks
Hiaburi



Re: Calculus... bleck - adsy - 03.04.2010

does this help?

Код:
GetXYInFrontOfPlayer(playerid, &Float:x, &Float:y, Float:distance)
{
	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));
}
use a negative for distance

usage

Код:
GetXYInFrontOfPlayer(playerid, xpos,ypos, -yourdistancebehind);



Re: Calculus... bleck - dracar - 03.04.2010

Thats nice, works for now, still dont understand it though lol


Re: Calculus... bleck - adsy - 03.04.2010

neither do i, credits to the person who made it. found as a stock on the wiki

https://sampwiki.blast.hk/wiki/Stocks


Re: Calculus... bleck - dracar - 03.04.2010

Well, thanks either way, couldn't figure out what to search for on the wiki to find it lol


Re: Calculus... bleck - Nero_3D - 03.04.2010

Quote:
Originally Posted by dracar
Thats nice, works for now, still dont understand it though lol
You want an explanation, mh, thats a good picture

The first number is cosine and the second after the comman sine (thats a unit circle), so


cos(0°) = 1, cos(90°) = 0, cos(180°) = -1, cos(270°) = 0 (calculates the X)
sin(0°) = 0, sin(90°) = 1, sin(180°) = 0, sin(270°) = -1 (calculates Y)

and the other numbers you only need to know for sure if you are gonna study

and because the angle in GTA San Andreas start at the "normal" 90° we just could do (Angle + 90.0) or the more famous methode switching the trigonometric functions and put a minus before the Angle

Or just read the en.wiki page about Unit circle (its not rly long)

Hope that helped a bit