How to get coordinates of point to the right of vehicle?
#1

It is hard to explain, I've prepared some screenshotes. So, it is a geometric question. Help me please with solution of this problem. How can I get coordinates of the point to the right of vehicle, based on vehicle coordinates and other information?
P.S. Vehicle ID - 588.
Reply
#2

GetVehicleZAngle
Reply
#3

Quote:
Originally Posted by Viniborn
Посмотреть сообщение
It returns vehicle Z rotation angle, but how can I get right point coordinates?
Reply
#4

may be unsure though
u can use combination of these functions IsPlayerInVehicle GetPlayerPos then Get x y coordinate and use IsPlayerinrangeofpoint
Reply
#5

The first step is to obtain the rotation.
The second is the position (X, Y, Z).

So trigonometry. Pythagoras, etc.
Reply
#6

Quote:
Originally Posted by Niko_boy
Посмотреть сообщение
may be unsure though
u can use combination of these functions IsPlayerInVehicle GetPlayerPos then Get x y coordinate and use IsPlayerinrangeofpoint
There is no solution in your answer) I need coordinates to create a pickup. So, if it is 0, 90, 180, 270 z angle, it is easy to get point coordinates, but I will deal with other angles.

Quote:
Originally Posted by Viniborn
Посмотреть сообщение
So trigonometry. Pythagoras, etc.
This is what I'm talking about, there must be geometric solution, but I have no idea how to do this, therefore I posted this question.
Reply
#7

Here an easy stock

pawn Код:
stock GetXYInDirection(& Float: X, & Float: Y, Float: Angle, Float: distance = 1.0) {
    X -= (floatsin(Angle, degrees) * distance);
    Y += (floatcos(Angle, degrees) * distance);
}
And how to use it in your example

pawn Код:
new
    Float: X,
    Float: Y,
    Float: Z,
    Float: A
;
GetVehiclePos(vehicleid, X, Y, Z);
GetVehicleZAngle(vehicleid, A);
GetXYInDirection(X, Y, (A - 90.0), 5.0); // (angle - 90) is the angle to the right
Reply
#8

Quote:
Originally Posted by Nero_3D
Посмотреть сообщение
Here an easy stock
...
Thank you! Will test it.
Reply
#9

Thanks again, it works fine! But can you give me theorems on which this solution is based on?
Reply
#10

On the unit circle



To get to the correct x we need cos and for y we need sin
Код:
x = cos(angle)
y = sin(angle)
The only thing we need to consider in sa-mp is that 0 degrees is 90 degrees in the unit circle, also we use
Код:
x = cos(angle + 90)
y = sin(angle + 90)
Another notation for that would be
Код:
x = -sin(angle)
y = cos(angle)
In the end we just add these cordinates to our original position
Код:
x = x - sin(angle)
y = y + cos(angle)
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)