Issue using cursor script with orthographic camera regarding co-ordinates (SOLVED)

Hi,

I’m using the cursor script together with the orthographic camera , and I’m having some issues.

(0,0) as picked by the cursor is different from the (0,0) for any game object I place. (0,0) for any game object is at the center of the screen whereas that shown by the cursor is the lower-left corner.

How do I change (0,0) picked by the cursor to the center of the screen? Any and all help is very much appreciated. Thanks.

You will have to pass translated input data to the cursor script as described here: https://github.com/britzl/defold-input/blob/master/in/cursor.md#input-handling

Use the screen_to_world() function of the camera to translate screen coordinates and then send them to the cursor script.

Let me know if you get stuck on this and I’ll try to create an example for you to check out.

4 Likes

We need an example. Thank you! :hugs:

1 Like

Added a new example to the repo. The important bit is this:

Here we take the on_input action.x and y and convert the coordinate from screen to translated world space and then pass that on to the cursor script. The HTML5 example is also update:

https://britzl.github.io/Defold-Input/

6 Likes

Thank you for showing the way. Think I figured it out.