velocity magnet +REP
#2

I did this some time ago, iirc it works pretty well (note that the target position must be higher than the player's position, otherwise they will not be moved (or die)).

Something like this (will pull a player to an object if they get close (25m)):

Код:
#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);
}
The closer the player is, the stronger the pull. You will have to adjust the total velocity (max_velocity), otherwise players will have no chance to get away from it.
Reply


Messages In This Thread
velocity magnet +REP - by bboytimix - 03.11.2017, 01:33
Re: velocity magnet +REP - by NaS - 03.11.2017, 18:18

Forum Jump:


Users browsing this thread: 1 Guest(s)