SA-MP Forums Archive
Trig problem, can't figure out left and right. - 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: Trig problem, can't figure out left and right. (/showthread.php?tid=94374)



Trig problem, can't figure out left and right. - Donny_k - 29.08.2009

Ok so if I use this code:

pawn Код:
x += ( distance * floatsin( -angle, degrees ) );
y += ( distance * floatcos( -angle, degrees ) );
It will give me the point infront or behind the x/y based on the distance variable (pos/neg value passed).

How do I do left or right though ?


Re: Trig problem, can't figure out left and right. - Weirdosport - 29.08.2009

I haven't looked into this much, but try swapping the X/Y formulae and seeing what the result is. Might be left/right.

EDIT: after some head scratching and mid-air hand gestures I think swapping them will work. To put something to the right you need a positive distance, and to the left a negative one. Things would be:

pawn Код:
x += ( distance * floatcos( -angle, degrees ) );
y += ( distance * floatsin( -angle, degrees ) );



Re: Trig problem, can't figure out left and right. - Donny_k - 29.08.2009

Edit: ignore this I'll read your edit and test it.


Re: Trig problem, can't figure out left and right. - Backwardsman97 - 29.08.2009

So you want to get a point next to it or like north east of it?


Re: Trig problem, can't figure out left and right. - Donny_k - 29.08.2009

@Wierdosport

Didn't test that code dude but it will just give an opposite effect as the sum is still the same but on the other axis.

@Backwardsman

I'm after a formula so that I can get the point to the left or right from a given point, not a compass point but a point based on my angle. The one above does it for forwards and backwards based on your angle but I'm having trouble working out left and right.

Edit:

Actually I will go and test it as I don't want to be an idiot and skip past it.

Edit 2:

Yep it does the same, no joy.


Re: Trig problem, can't figure out left and right. - Weirdosport - 29.08.2009

It wont give an opposite effect, that is done by changing -angle to angle. By changing which axis you alter, I am reasonably confident it would give the desired effect. I've tested it on 90 degree angles and it gave the results I'd expect.


Re: Trig problem, can't figure out left and right. - Donny_k - 29.08.2009

Edit:

This is the working one:

pawn Код:
x += ( distance * floatcos( angle, degrees ) );
y += ( distance * floatsin( angle, degrees ) );
I removed the '-' from the angle, it works like a treat from what I've just tested (hope I've not spoken to soon lol).

I got confused before when you said the opposite is the correct one, I thought you meant the distance so as you can imagine that didn't work and just went the other way hehe.

Thanks for the help dude, I appreciate it !