20.03.2015, 13:35
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
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