Get back of player
#1

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

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

How to get nearest border?
Reply
#4

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

Current i have polygon, createdynamicpolygon, how to calculate?
Reply
#6

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

I don't understand that formulas...
Reply
#8

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.
Reply
#9

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

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 код:
FloatDistanceLinePoint2D(Floatx1Floaty1Floatx2Floaty2Floatx3Floaty3) {
    
x2 -= x1// x1, y1 - x2, y2 is the line - direction doesn't matter
    
y2 -= y1// x3, y3 is the point
    
return VectorSize(0.00.0x2 * (y3 y1) - y2 * (x3 x1)) / VectorSize(x2y20.0);

You need to loop through your points array (from the polygon) and find the smallest distance
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)