Author Topic: How to use ScreenPosToWorld?  (Read 912 times)

Theremin

  • Full Member
  • ***
  • Posts: 154
  • Karma: +48/-18
  • Worst Server Owner
    • View Profile
    • Visit my YouTube channel
How to use ScreenPosToWorld?
« on: October 07, 2015, 10:46:16 pm »
How to use ScreenPosToWorld? It either returns false or crashes my client. I saw a fourth parameter has been added in 0.1.0.15 update:
Quote
Scripting - Added a depth parameter to ScreenPosToWorld (client) - ScreenPosToWorld( float x, float y, float depth ), ScreenPosToWorld( Vector3 pos, float depth )
then Vortrex wrote something about the fact that it wasn't working:
Quote
ScreenPosToWorld is now not working.
It returns an instance in Vector form like it should, but ...
The vector is composed of "1.#R 1.#R 1.R"
Each object in the instance is "1.#QNAN"
It should be noted that typeof returns Vector, but its unusable.
Can somebody provide a working example?

sasha19323

  • Jr. Member
  • **
  • Posts: 99
  • Karma: +25/-24
    • View Profile
Re: How to use ScreenPosToWorld?
« Reply #1 on: October 08, 2015, 12:05:06 pm »
It works weird, but:
Code: ("Client-side") [Select]
function onScriptLoad()
{
  ShowMouseCursor(true);
  fDepth <- 10.0;
}
function onClientMouseClick(button, down, x, y)
{
  if (down)
  {
   local pos = ScreenPosToWorld(VectorScreen(x, y), fDepth);
   CallServerFunc(YOUR_PATH_HERE, "CreateObject2", 1344, pos.x, pos.y, pos.z);
  }
}
Code: ("Server-side") [Select]
RegisterRemoteFunc("CreateObject2");
function CreateObject2(model, x, y, z) { CreateObject(model, Vector(x,y,z)); } //CallServerFunc doesn't work w/ Vector class, no idea why

 

© Liberty Unleashed Team.