SA-MP Forums Archive
SetPlayerVelocity help. - 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: SetPlayerVelocity help. (/showthread.php?tid=568184)



SetPlayerVelocity help. - De4dpOol - 20.03.2015

Hello,
I want to know what should be the values to move the player towards a specific x, y, z.
For example: I want to move the player frpm pX, pY, pZ to x, y, z at a speed of 10. How to get the values to be used in SetPlayerVelocity.
Thank you.


Re: SetPlayerVelocity help. - AIped - 20.03.2015

i think in your case its best to set the vehicle facing angle towards that position and make the velocity go forward with the speed of 10


Re: SetPlayerVelocity help. - De4dpOol - 20.03.2015

Quote:
Originally Posted by AIped
Посмотреть сообщение
i think in your case its best to set the vehicle facing angle towards that position and make the velocity go forward with the speed of 10
First, I am setting player's velocity not a vehicle. Secondly, what to set his facing angle? I don't know where the target XYZ are? even if I got the angle. It will require Speed X, Speed Y, Speed Z to use in SetPlayerVelocity so that he moves towards the point.


Re: SetPlayerVelocity help. - fuckingcruse - 20.03.2015

Can you explain your self clearly ? You want a pleyer to move fast? or slow?


Re: SetPlayerVelocity help. - De4dpOol - 20.03.2015

Quote:
Originally Posted by fuckingcruse
Посмотреть сообщение
Can you explain your self clearly ? You want a pleyer to move fast? or slow?
I want him to move in a specific direction. Speed can be anything.


Re: SetPlayerVelocity help. - IzadorO - 20.03.2015

With the SetPlayerVelocity function, you have X, Y & Z. If you set the X function to make the player go that direction & go faster, he will go in that direction & will go faster, and vice versa for all of the other axis. You cannot make the player face the way in which the velocity function sets them, they have to face that way themselves. You would need to use another function for setting the way they are facing to the velocity one.


Re: SetPlayerVelocity help. - De4dpOol - 20.03.2015

Quote:
Originally Posted by IzadorO
Посмотреть сообщение
With the SetPlayerVelocity function, you have X, Y & Z. If you set the X function to make the player go that direction & go faster, he will go in that direction & will go faster, and vice versa for all of the other axis. You cannot make the player face the way in which the velocity function sets them, they have to face that way themselves. You would need to use another function for setting the way they are facing to the velocity one.
I didn't understand you! I know Speed X value will move them on x axis and Speed Y will move them on y axis. Thats not I want to know. There is a possible way to get the value SpeedX, SpeedY and SpeedZ value that will move them to X, Y, Z. I just want to know that way because my math is not good.


Re: SetPlayerVelocity help. - bartekdvd - 20.03.2015

The math behind it (move along straight line):

def Vector = (x,y,z)
Vector from = (0,0,0)
Vector to = (1,1,0)
Vector ft = to - from = (1,1,0) - (0,0,0) = (1,1,0)
float length = squareroot(ft.x*ft.x + ft.y*ft.y + ft.z*ft.z) = squareroot(1 + 1 + 0) = 1.41421...
Vector unit = ft/length = (1/1.41, 1/1.41, 0/1.41) = (0.709..., 0.709..., 0)
float speed = 0.5
Vector velocity = speed*unit = (0.5*0.71, 0.5*0.71, 0) = (0.355, 0.355, 0)

SetPlayerVelocity(playerid, velocity.x, velocity.y, velocity.z)

This is pseudo code. If you will understand it you will easily translate it to PAWN.
The key is unit vector: http://en.wikipedia.org/wiki/Unit_vector


Re: SetPlayerVelocity help. - De4dpOol - 20.03.2015

Quote:
Originally Posted by bartekdvd
Посмотреть сообщение
The math behind it (move along straight line):

def Vector = (x,y,z)
Vector from = (0,0,0)
Vector to = (1,1,0)
Vector ft = to - from = (1,1,0) - (0,0,0) = (1,1,0)
float length = squareroot(ft.x*ft.x + ft.y*ft.y + ft.z*ft.z) = squareroot(1 + 1 + 0) = 1.41421...
Vector unit = ft/length = (1/1.41, 1/1.41, 0/1.41) = (0.709..., 0.709..., 0)
float speed = 0.5
Vector velocity = speed*unit = (0.5*0.71, 0.5*0.71, 0) = (0.355, 0.355, 0)

SetPlayerVelocity(playerid, velocity.x, velocity.y, velocity.z)

This is pseudo code. If you will understand it you will easily translate it to PAWN.
The key is unit vector: http://en.wikipedia.org/wiki/Unit_vector
Yes! it works bro thanks. +rep