Working out a position with just X,Y,Z - 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)
+--- Thread: Working out a position with just X,Y,Z (
/showthread.php?tid=306664)
Working out a position with just X,Y,Z -
Kyle - 27.12.2011
Hi, I need a function for it to work out the position of the checkpoint exit position look in the image below:
The brown line = Wall
Blue dot = CP
Red X = Where I want the exit pos to be.
If I have the x,y,z of the CP can I find out the x,y,z of the red X?
Kyle
Thanks!
Re: Working out a position with just X,Y,Z -
Babul - 27.12.2011
does your checkpoint data include an angle for the checkpoint? providing one, you can calculate the exit point with the sinus/cosinus functions. with the walls orientation, the angle of the checkpoint could be calculated aswell.
presuming your checkpoint coordinates are cX,cY,cZ,cA, and Radius is like 5 units, this should give you some results:
Код:
new cXNew=Radius*floatsin(cA+180,degrees);
new cYNew=Radius*floatcos(cA+180,degrees);
you noticed the 180 - in your example the wall is at north, thats 0 degrees. rotate (sour skin) 180 degrees, then you watch away from that wall. step forward 5 units, then you got back to your desired position. the same trick will work on any wall rotation, just think about a 90 degrees rotated wall: the sinus will be 0, where the cosinus is 1. the cosinus axis result adds the radius (5) multiplied with the bias (cosinus value=1) == 5 to the left (90 plus 180= 270, thats the left side)
i typed this out of my mind, w/o checking...