How do I use a mouse cursor with a 3d camera?

0 favourites
  • 6 posts
From the Asset Store
Mouse cursor is something that the player controls and sees all the time, that's why it is so important to make it cool!
  • I appear to be having some issues with a mouse cursor if I have a 3D Camera enabled.

    I want the cursor to always be rendered on top of everything else, so I have it set on a 2D layer. When I do this, the cursor no longer stays on the mouse's x and y pos so long as I have the 3d camera enabled.

    Why is this? Why are 2d layers affected by 3d cameras?

    I mocked up a quick example. Feel free to check it out.

    https://1drv.ms/u/s!AlZkRk7KfdFFivsjA7O4P3LQrRDW0g?e=0iTe6y

    Is this intended by design? Seems... for lack of a better word... useless for game development. When would you not want a sprite to stick to the mouse if you set it to the mouse's x and y? I'd have thought a sprite on a 2d layer would follow the mouse.

    However, if you open debug and look at the mouse object, it shows a different x and y position for each layer. There's no way I can use this data from what I can tell.

    I want the sprite to appear on the HUD layer, but get its positioning from the 3D layer, apparently.

    Also, I know I could replace the cursor with a sprite, and that works, but for my actual game, rather than a sprite, I'm using particles.

    Any ideas?

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • I can't open your project, but would being able to get the mouse position on different layers help?

    You can do that with the mouse expression Mouse.X(layer).

  • Thanks, R0J0hound. That did the trick, but strangely enough I had to tell the sprite on the 2D "Cursor" layer to set its X and Y to mouse.x("Cursor") rather than the 3D layer I expected.

    Makes sense if you think about it, but I'd have thought that would be default behaviour.

  • I think the default is mouse.x just grabs the bottom layer. I think it would be complicated for construct to automatically guess what layer to grab the position from or it may just be impossible most of the time to make a good guess.

  • I think the default is mouse.x just grabs the bottom layer. I think it would be complicated for construct to automatically guess what layer to grab the position from or it may just be impossible most of the time to make a good guess.

    You're correct. My bottom layer is indeed 3D.

    However, I'm having a similar issue trying to get the sprite on the 3D layer to follow the cursor on the 2D layer if controlled by something other than mouse, such as a gamepad or a keyboard.

    Sprite.X("Layer") isn't a thing, unfortunately.

    My guess is I'll need to multiply its position based on the Z difference?

  • There are the layertocanvas and canvasToLayer system expressions that may help there. At least when the object on the 3d layer has a zelevation of 0.

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