Get camera position: Difference between revisions

(Transferred the page from the old wiki)
 
(Fixed broken link)
 
(One intermediate revision by the same user not shown)
Line 1: Line 1:
Unfortunately, there is no built-in "Get Camera" block.
Unfortunately, there is no built-in "Get Camera" block.
The easiest way to get around that is to save the camera's parameters in [[global variables|Variable#Global variables]] while (or instead of) setting them with Set Camera, then reading from them when needed.
The easiest way to get around that is to save the camera's parameters in [[Variables#Global variables|global variables]] while (or instead of) setting them with Set Camera, then reading from them when needed.


If that's not an option for you (for example, if you're making a custom block for <i>everyone</i> to use), it <i>is</i> possible to calculate the camera's parameters with [[Screen To World]] and some clever math.
If that's not an option for you (for example, if you're making a custom block for <i>everyone</i> to use), it <i>is</i> possible to calculate the camera's parameters with [[Screen To World]] and some clever math.
Line 6: Line 6:
If that's not a problem for you, [https://play.fancade.com/5C67367D142708D2 here's] an example by [[The Questers#Mathias Elgaard|Mathias Elgaard]].
If that's not a problem for you, [https://play.fancade.com/5C67367D142708D2 here's] an example by [[The Questers#Mathias Elgaard|Mathias Elgaard]].
(Or try to figure it out yourself, it's fun!)
(Or try to figure it out yourself, it's fun!)
[[Category:Scripting]]

Latest revision as of 21:26, 4 July 2024

Unfortunately, there is no built-in "Get Camera" block. The easiest way to get around that is to save the camera's parameters in global variables while (or instead of) setting them with Set Camera, then reading from them when needed.

If that's not an option for you (for example, if you're making a custom block for everyone to use), it is possible to calculate the camera's parameters with Screen To World and some clever math. However, this will lag behind the real camera by one frame, as Screen to World uses the current frame's camera, while Set Camera affects the next frame. If that's not a problem for you, here's an example by Mathias Elgaard. (Or try to figure it out yourself, it's fun!)