godotengine / godotengine/godot
[CharacterBody2D.get_platform_velocity] behaves differently based on framerate
- Dominant language
- C++
- Stars
- 117k
- Forks
- 26.8k
- PR merge metrics
- PR metrics pending
Description
### Tested versions
Tested in v4.4.stable.official [4c311cbee], originally noticed the issue in v4.3
### System information
Godot v4.4.stable - Windows 10 (build 19045) - Multi-window, 2 monitors - Vulkan (Forward+) - dedicated GeForce GTX 1660 Ti - Intel(R) Core(TM) i5-9300HF CPU @ 2.40GHz (8 threads)
### Issue description
I use Godot Engine with the default 2D physics engine. [CharacterBody2D.get_platform_velocity] behaves as expected in 60FPS but not in 30FPS, though the character still moves in the same way. Specifically [get_platform_velocity] returns (0, 0) every other frame when the character is on a moving platform.
### Steps to reproduce
Download the MRP and start the game. Jump to the moving platform. Every frame, the player character takes the result of [get_platform_velocity] and prints it. When in 60FPS the value seems correct but in 30FPS, the method returns (0, 0) every other frame.
I discovered this because I use Godot Engine on my laptop. The system locks the game's framerate at 30FPS when unplugged, but runs it at 60FPS when plugged. Plugging and deplugging the computer while the game is running makes it switch behavior. The bug also occurs when the "max FPS" is set at 30FPS through the project settings, unless "physics ticks per second" is also set to 30FPS. The bug probably occurs whenever the physics framerate and rendering framerate are not the same. I also tested with physics framerate at 60FPS and rendering framerate at 59FPS, and it does seem like there are 59 frames with correct values followed by one at (0, 0).
### Minimal reproduction project (MRP)
[mrp_platform_velocity_fps.zip](https://github.com/user-attachments/files/19198961/mrp_platform_velocity_fps.zip)
Contributor guide
Research direction
Start by running the attached mrp_platform_velocity_fps.zip project and compare CharacterBody2D.get_platform_velocity at 60 FPS and 30 FPS, with different physics tick rates. Trace the get_platform_velocity entry point and platform-motion update path. Done means the method returns the expected platform velocity consistently when rendering and physics rates differ.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- cpp
- Domain
- game-dev
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 42/100