getWorldFromScreenPosition | Multi Theft Auto: Wiki Skip to content

getWorldFromScreenPosition

Client-side
Server-side
Shared

Manual Review Required

Please finish this page using the corresponding Old Wiki article. Go to Contribution guidelines for more information.


This function allows you to retrieve the world position corresponding to a 2D position on the screen, at a certain depth.

Syntax

float,​ float,​ float getWorldFromScreenPosition ( float x, float y, float depth )
Required Arguments
  • x: A float value indicating the x position on the screen, in pixels.
  • y: A float value indicating the y position on the screen, in pixels.
  • depth: A float value indicating the distance from the camera of the point whose coordinates we are retrieving, in units.

Returns

  • float: x
  • float: y
  • float: z

Returns three x , y , z floats indicating the world position if successful, false otherwise.

Code Examples

shared

This example binds the local player's "i" key to a function that creates an explosion in the middle of the screen.

function explosion ()
local w, h = guiGetScreenSize ()
local x, y, z = getWorldFromScreenPosition ( w/2, h/2, 10 )
createExplosion ( x, y, z, 11 )
end
bindKey ( "i", "down", explosion )

See Also

World Functions