GetVectorAngle Shared function
Jump to navigation
Jump to search
This function was added in version: 0.0.0 |
The function is calculates the angle based on the positions of the two objects.
Syntax
int getVectorAngle(float x1, float z1, float x2, float z2)
Required Arguments
- x,z - Position of the first object.
- x2,z2 - Position of the second object.
Returns
- int: The function returns angle directed towards the object.
Example
local function commandHandler(pid, cmd, params)
{
if (cmd == "look")
{
lookAt(pid,params);
}
}
addEventHandler("onPlayerCommand", commandHandler);
function lookAt(pid,params)
{
local args = sscanf("d",params);
if (args)
local pos = getPlayerPosition(pid);
local pos2 = getPlayerPosition(args[0]);
local angle = getVectorAngle(pos.x,pos.z,pos2.x,pos2.z);
setPlayerAngle(pid,angle);
sendMessageToPlayer(pid,255,255,255,"You now look at " + getPlayerName(args[0]));
else
sendMessageToPlayer(pid,255,0,0,"Type: /look [playerID]");
}