GetVectorAngle Shared function

From Gothic 2 Online: Wiki
Revision as of 13:45, 23 March 2017 by Patrix (talk | contribs) (Required Arguments)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
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.


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.


  • int: The function returns angle directed towards the object.


local function commandHandler(pid, cmd, params)
	if (cmd == "look")

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);
		sendMessageToPlayer(pid,255,255,255,"You now look at " + getPlayerName(args[0]));
		sendMessageToPlayer(pid,255,0,0,"Type: /look [playerID]");

Related functions