PrimaryPointerInfo screenCoordinates/screenDelta use bottom-left Y-up instead of top-left Y-down

Open Beginner friendly
#10,073 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Assessment

Difficulty
2/5
Estimated time
1-3 hours
Newbie friendliness
84/100
Issue type
Bug
Clarity
Clearly specified
Activity status
Active
Tech stack
csharp, unity
Domain
game-dev

Research direction

Start in Explorer/Assets/DCL/SDKComponents/PrimaryPointerInfo/Systems/PrimaryPointerInfoSystem.cs at UpdatePointerInfo(), where inputPoint and Camera.Delta are assigned to ScreenCoordinates and ScreenDelta. Validate with the minimal SDK7 repro scene: the red square should stay under the cursor, and moving the mouse down should log a positive delta.y as in Bevy and Godot.

Written by the indexing model from the issue text.

Description

1-high bug sdk

Summary

PrimaryPointerInfo.screenCoordinates and screenDelta are reported with a bottom-left origin / Y up (Unity's native screen space). Bevy and Godot report top-left origin / Y down, which is also the coordinate space of UiTransform / UiCanvasInformation. Scenes that compare the pointer against UI rects, or feed screenDelta into a VirtualCamera look, get a vertically mirrored cursor and inverted pitch on Unity only.

Where

Explorer/Assets/DCL/SDKComponents/PrimaryPointerInfo/Systems/PrimaryPointerInfoSystem.csUpdatePointerInfo() writes inputPoint.ReadValue<Vector2>() (Unity screen space, Y up) and the accumulated Camera.Delta straight into ScreenCoordinates / ScreenDelta.

For comparison:

  • Bevy: crates/scene_runner/src/update_scene/pointer_lock.rs uses Window::cursor_position() (top-left, Y down) and the mouse-motion delta (Y down).
  • Godot: lib/src/scene_runner/scene_manager.rs uses the viewport mouse position (top-left, Y down) and its frame difference.

The SDK docs specify a top-left origin with Y increasing downward, matching UiTransform. The proto comment only says "screen space (pixels)", so documenting the convention there too would help. Suggested fix: y = Screen.height - y for the position and negate delta.y.

This was reported for screenCoordinates in #8757 (closed by the stale bot, not fixed); this issue adds the screenDelta half and a repro scene.

How to validate

Minimal SDK7 scene: a 40x40 square follows the pointer using screenCoordinates in UI canvas space, and the log prints the delta sign while the pointer is locked.

import { engine, PrimaryPointerInfo, UiCanvasInformation, PointerLock } from '@dcl/sdk/ecs'
import ReactEcs, { ReactEcsRenderer, UiEntity } from '@dcl/sdk/react-ecs'
import { Color4 } from '@dcl/sdk/math'

export function main() {
  ReactEcsRenderer.setUiRenderer(() => {
    const cursor = PrimaryPointerInfo.getOrNull(engine.RootEntity)?.screenCoordinates
    const canvas = UiCanvasInformation.getOrNull(engine.RootEntity)
    if (!cursor || !canvas) return null
    return (
      <UiEntity
        uiTransform={{
          positionType: 'absolute',
          position: { left: cursor.x - 20, top: cursor.y - 20 },
          width: 40,
          height: 40,
          pointerFilter: 'none'
        }}
        uiBackground={{ color: Color4.Red() }}
      />
    )
  })

  engine.addSystem(() => {
    if (!PointerLock.getOrNull(engine.CameraEntity)?.isPointerLocked) return
    const delta = PrimaryPointerInfo.getOrNull(engine.RootEntity)?.screenDelta
    if (delta && Math.abs(delta.y) > 2) console.log(delta.y > 0 ? 'delta.y > 0' : 'delta.y < 0')
  })
}

Expected (Bevy, Godot): the red square sits under the cursor; moving the mouse down logs delta.y > 0.
Actual (Unity): the square is mirrored vertically (top of screen when the cursor is at the bottom); moving the mouse down logs delta.y < 0.

Dominant language
C#
Stars
23
Forks
17
Avg merge
2d 4h
Merged PRs (30d)
102

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from decentraland/unity-explorer

All issues in decentraland/unity-explorer

Similar issues

More C# issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.