Calculate vector position based on angle and direction
#1

I am wanting to get 2 new positions 3 units away from 2 current positions based on the angle between the points in samp.
I made a little thingy to help illustrate it better:


Going from point A to B their is a 18.4° angle from the north, im samp that is 341.57°, I want to find the (X,Y) cords of C and D, where C is 3 units away from A and D is 3 units away from B.


I also want this to work for I can calculate 2 points 3 units away on the opposite side of the line when your going from B to A.


Ill be sure to give you rep if you can come up with a formula for this
Reply
#2

The basic formula I use to calculate a point INFRONT of a player is:
Код:
x += 3 * floatsin(-a, degrees);
y += 3 * floatcos(-a, degrees);
As you want to get a point next to it instead of infront, you could just adjust the "a" (angle).
Let's say 90 degrees -> a -= 90;
Reply
#3

Just add another 90 degrees and then you can get from A to C using the 'facing forward' code. Its coords are 3(sin(18.4+90),cos(18.4+90)). Then to get D just do C+B-A. In GTASA reverse degrees it's like this:
Код:
cx += 3 * floatsin(-a-90, degrees);
cy += 3 * floatcos(-a-90, degrees);
dx = cx + ax - bx;
dy = cy + ay - by;
Or you can just calculate D from B the same way.
Reply
#4

I found a solution: sometimes I was unable to correctly get the angle between two points based on the north so instead, when the npc is moving, I just got their facing angle and then used that to find the correct position I want for the next point.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)