GetWorldFromScreenPosition: Difference between revisions

From Multi Theft Auto: Wiki
Jump to navigation Jump to search
Line 5: Line 5:
==Syntax==
==Syntax==
<syntaxhighlight lang="lua">
<syntaxhighlight lang="lua">
float float float getWorldFromScreenPosition ( float x, float y )
float float float getWorldFromScreenPosition ( float x, float y, float z )
</syntaxhighlight>
</syntaxhighlight>



Revision as of 12:53, 11 August 2007

This function allows you to retrieve the world position corresponding to the 2D position on the screen.

Syntax

float float float getWorldFromScreenPosition ( float x, float y, float z )

Required Arguments

  • x: A float value between 0 and 1 indicating the x position on the screen.
  • y: A float value between 0 and 1 indicating the y position on the screen.

Returns

Returns three floats indicating the world position, x, y and z respectively, false otherwise.

Example

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

function explosion ( key, keyState )
  local x, y, z = getWorldFromScreenPosition ( 0.5, 0.5 )
  createExplosion ( x, y, z, 11 )
end
bindKey ( "i", "down", "create explosion", explosion )

See Also