Get back of player -
MerryDeer - 10.09.2016
Hi,
How to get back of player? i'am now using GetXYInBackOfPlayer, and AC_SetPlayerPosFindZ, what i want to do if player out from area teleport him back some meters. If he out, some time i give him kick, but there is times that player position is changing and he is teleport out from area, of course he get warnings, and kick that he is not in area. How to fix that?
Re: Get back of player -
Nero_3D - 10.09.2016
Well get the nearest border of your area and teleport him there because the back of the player could be anywhere (like when he is moving backwards)
Re: Get back of player -
MerryDeer - 10.09.2016
How to get nearest border?
Re: Get back of player -
Nero_3D - 10.09.2016
Depends on your area, is it a circle, a rectangle, a square or even a polygon
If you have a circle you just need to check if the distance from the middle of it and the player is higher than the radius and set him back to the radius
For a rectangle you get the x and the y distance and set the either x or the y value depends on which border the player is
Re: Get back of player -
MerryDeer - 10.09.2016
Current i have polygon, createdynamicpolygon, how to calculate?
Re: Get back of player -
Nero_3D - 10.09.2016
Well you needs to calculate the shortest distance from
line to
point (
usually done with the cross product)
The
line would be point 1 to point 2 from your polygon and so on (p2 to p3, p3 to p4, ..., pn to p1)
The
point would be the player position
Calculate the distances and find the nearest one
Re: Get back of player -
MerryDeer - 11.09.2016
I don't understand that formulas...
Re: Get back of player -
PrO.GameR - 11.09.2016
Back of the player? get players facing angle, calculate a position with opposite of that with a 1 meter relative pos, it's literally one sin/cos away from you -_- (For sa-mp tho you'd need to use the angle itself)
Here's another hint, relative pos*sin + x, relativepos*cos + y
Thats as much help I can provide without literally giving you the code, if you can't write that ^ in pawn you need to learn more about pawn.
@Nero When calculating infront of something or behind it is usually 2D and sometimes a Z finder, hence it'd turn into a point relative to another point, that makes it too complicated.
Re: Get back of player -
MerryDeer - 11.09.2016
No, i just use back of player to back player, all i want to do don't let player out from zone, without using setplayerworldboundries
Re: Get back of player -
Nero_3D - 11.09.2016
Maybe I should have given you the 2d link
http://mathworld.wolfram.com/Point-L...mensional.html
Although I don't think that it is any better because the result is the same formula
Thats it
PHP код:
Float: DistanceLinePoint2D(Float: x1, Float: y1, Float: x2, Float: y2, Float: x3, Float: y3) {
x2 -= x1; // x1, y1 - x2, y2 is the line - direction doesn't matter
y2 -= y1; // x3, y3 is the point
return VectorSize(0.0, 0.0, x2 * (y3 - y1) - y2 * (x3 - x1)) / VectorSize(x2, y2, 0.0);
}
You need to loop through your points array (from the polygon) and find the smallest distance