Mouse to world position

0 favourites
  • 8 posts
From the Asset Store
Total customisation of the input! You can combine inputs from all peripherals. Make your game accessible for everyone!
  • Hello. Does anyone have a formula for calculating mouse click position with a 3D camera?

    The usual methods are not suitable.

  • Do you like math :D ? You can calculate the position using the angle of the camera...

    or there is already some inbuilt expressions for this:

    https://www.construct.net/en/make-games/manuals/construct-3/plugin-reference/3d-camera

    CanvasToLayerX(layer, x, y, layerZ)

    CanvasToLayerY(layer, x, y, layerZ)

    Transform a position in canvas co-ordinates to layer co-ordinates on a Z plane given by layerZ. This is similar to the system expressions of the same name, but working in 3D.

    LayerToCanvasX(layer, x, y, z)

    LayerToCanvasY(layer, x, y, z)

    Transform a position in 3D layer co-ordinates to 2D canvas co-ordinates. This is similar to the system expressions of the same name, but working in 3D.

  • Do you like math :D ? You can calculate the position using the angle of the camera...

    or there is already some inbuilt expressions for this:

    https://www.construct.net/en/make-games/manuals/construct-3/plugin-reference/3d-camera

    CanvasToLayerX(layer, x, y, layerZ)

    CanvasToLayerY(layer, x, y, layerZ)

    Transform a position in canvas co-ordinates to layer co-ordinates on a Z plane given by layerZ. This is similar to the system expressions of the same name, but working in 3D.

    LayerToCanvasX(layer, x, y, z)

    LayerToCanvasY(layer, x, y, z)

    Transform a position in 3D layer co-ordinates to 2D canvas co-ordinates. This is similar to the system expressions of the same name, but working in 3D.

    Oh right. I should have checked the documentation first :)

    Thanks! I'll take a look and post the results here.

  • Do you like math :D ? You can calculate the position using the angle of the camera...

    or there is already some inbuilt expressions for this:

    https://www.construct.net/en/make-games/manuals/construct-3/plugin-reference/3d-camera

    CanvasToLayerX(layer, x, y, layerZ)

    CanvasToLayerY(layer, x, y, layerZ)

    Transform a position in canvas co-ordinates to layer co-ordinates on a Z plane given by layerZ. This is similar to the system expressions of the same name, but working in 3D.

    LayerToCanvasX(layer, x, y, z)

    LayerToCanvasY(layer, x, y, z)

    Transform a position in 3D layer co-ordinates to 2D canvas co-ordinates. This is similar to the system expressions of the same name, but working in 3D.

    I don't understand what this expression returns. It's just other numbers that also don't match the cursor position in 3D space.

    Okay, in my project I'll try to use all planes with z = 0 and Mouse.x("Layer 1"). Then the created object gets the correct position.

    Maybe in the future I'll figure it out, but for now it's very difficult.

  • Try Construct 3

    Develop games in your browser. Powerful, performant & highly capable.

    Try Now Construct 3 users don't see these ads
  • You have to use mouse position to calculate cavas to layer. The layer you select needs to be the one where you want the selection to take place on. If that layer has a different z level than what you are looking to click, if won't seem right.

    I'm going to jump in a project so I can share the details

  • Okay, I wasn't using this right either. I find bugs as soon as I moved the 3d camera. I've searched around for other answers and found one from newt that said to simply use mouse.x and mouse.y position. That also seems to not work. I'm using the ghost racer example and spawning a flash object where my mouse position is, just that it only works when the camera isn't moved and left at default.

  • Okay, I wasn't using this right either. I find bugs as soon as I moved the 3d camera. I've searched around for other answers and found one from newt that said to simply use mouse.x and mouse.y position. That also seems to not work. I'm using the ghost racer example and spawning a flash object where my mouse position is, just that it only works when the camera isn't moved and left at default.

    Yes, that's right. If the surface is at z=0 – mouse.x, mouse.y will work correctly.

    I tried changing the Look At Z camera and trying with ground above 0 Z elevation, but that didn't work.

Jump to:
Active Users
There are 1 visitors browsing this topic (0 users and 1 guests)