SetPlayerVelocity help.
#1

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

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

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

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

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

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

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

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

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
Reply


Forum Jump:


Users browsing this thread: 2 Guest(s)