Calculus... bleck
#1

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
Reply
#2

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);
Reply
#3

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

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

https://sampwiki.blast.hk/wiki/Stocks
Reply
#5

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

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
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)