Search Unity

  1. Unity Asset Manager is now available in public beta. Try it out now and join the conversation here in the forums.
    Dismiss Notice
  2. Unity 6 Preview is now available. To find out what's new, have a look at our Unity 6 Preview blog post.
    Dismiss Notice
  3. Unity is excited to announce that we will be collaborating with TheXPlace for a summer game jam from June 13 - June 19. Learn more.
    Dismiss Notice

Input position relative to canvas in webgl

Discussion in 'Project Tiny' started by exoainteractive, Jan 22, 2021.

  1. exoainteractive


    Jan 21, 2017
    In the examples InputSystem::GetInputPosition() is used to get the position of the mouse. In webgl that position given is relative to the browser page, but we would need to have the mouse position in the canvas coordinates instead for the cases where the canvas is not fullscreen.

    In the example attached, P0 at the bottom left of the canvas should be (0;0) but it's (100;-100) and P1 should be (300;300) but it's (400;200), so basically the position of the canvas inside the page is not taken into account.

    Thanks for your help!

    Attached Files:

    Last edited: Jan 22, 2021