03.11.2017, 01:33
hey is there any method to magnet player to a specific OBJECT/objectX,objectY,objectZ using velocity...
#define pull_distance (25.0) #define max_velocity (0.4) new Float:tX, Float:tY, Float:tZ, Float:pX, Float:pY, Float:pZ, Float:vX, Float:vY, Float:vZ, Float:vLen; GetObjectPos(objectid, tX, tY, tZ); // Get target position (object in this case) GetPlayerPos(playerid, pX, pY, pZ); vX = tX - pX; // Get the difference between target and player vY = tY - pY; vZ = tZ - pZ; vLen = VectorSize(vX, vY, vZ); // Get the distance (vector length) if(vLen <= pull_distance) { vX = vX / vLen * max_velocity; // Divide the Vector by its size to get a vector of size 1.0m, and limit it to the maximum velocity vY = vY / vLen * max_velocity; vZ = vZ / vLen * max_velocity; vLen = (pull_distance - vLen) / pull_distance; SetPlayerVelocity(playerid, vX * vLen, vY * vLen, vZ * vLen); }