godotengine / godotengine/godot

mouse_position is not consistent in one _process() call in Godot 4

Open
#89,109 10 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

bug discussion topic:input topic:platforms
Dominant language
C++
Stars
117k
Forks
26.8k
PR merge metrics
PR metrics pending

Description

Tested versions

Reproducible in: v4.3.dev4 [df78c0636], v4.2.1.stable [b09f793f5] - Not reproducible in: v3.5.3.stable [6c814135b]

System information

Godot v4.3.dev4.mono - Windows 10.0.22631 - Vulkan (Forward+) - dedicated NVIDIA GeForce RTX 4050 Laptop GPU (NVIDIA; 31.0.15.4626) - AMD Ryzen 5 7640HS w/ Radeon 760M Graphics (12 Threads)

Issue description

get_local_mouse_postion() or get_global_mouse_position() returns different coordinates call by call in one _process().

[EDIT] Turns out (thanks to comments below) this is due to a ''feature'' of DisplayServer.mouse_get_position(), which returns the mouse position out of the Godot frame system. Discussion on design may be needed.

Steps to reproduce
  1. Create a new project and a scene with any root node
  2. Add a CanvasLayer as a child
  3. Add a ColorRect as a child node of the layer, use PRESET_FULL_RECT anchors
  4. Attach the script below to the ColorRect
  5. Run the scene and move mouse around quickly
  6. In my laptop get_local_mouse_position() and get_global_mouse_position() are not consistent
extends ColorRect

func _process(_delta: float) -> void:
	var global_position_first = get_global_mouse_position()
	var global_position_second = get_global_mouse_position()
	var position_first = get_local_mouse_position()
	var position_second = get_local_mouse_position()
	
	if global_position_first != global_position_second:
		print(global_position_first, global_position_second, " Why global position D:")
	if position_first != position_second:
		print(position_first, position_second, " Why local position D:")
Minimal reproduction project (MRP)

N/A

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.

Research direction

Start with DisplayServer.mouse_get_position() and the get_local_mouse_position()/get_global_mouse_position() calls shown in the reproduction script. Reproduce the discrepancy in Godot 4 by calling each method twice in one _process() call, then review the issue discussion to establish the intended frame-coordinate behavior. Done requires a resolved behavior or documented design decision.

Written by the indexing model from the issue text.

Assessment

Domain
game-dev
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
28/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.