godotengine / godotengine/godot
CharacterBody2D slide breaks on uneven-scaled StaticBody2D
- Dominant language
- C++
- Stars
- 117k
- Forks
- 26.8k
- PR merge metrics
- PR metrics pending
Description
### Tested versions
- Reproducible in 4.2.1 stable [b09f793f5]
### System information
Windows 10.0.22621 - Vulkan (Forward+) - dedicated NVIDIA GeForce RTX 3050 Laptop GPU (NVIDIA; 31.0.15.4617) - 12th Gen Intel(R) Core(TM) i5-12500H (16 Threads)
### Issue description
#### Issue:
If a CharacterBody2D tries to slide on a StaticBody2D that has a collision shape with uneven-scaling (X scale doesn't match Y scale) and hits an edge not axis-aligned (so, at an angle), it appear to quickly slide (sometimes instantly) to one vertex of the shape.
#### Expected:
The CharacterBody2D slide velocity is independent of the object's scale.
#### Demo:
https://github.com/godotengine/godot/assets/74799857/51d85a52-b824-4250-a8a5-459fdaefc8eb
#### Details:
The difference between the scales will magnify the process. A scale of (0.5, 0.52) will have the CharacterBody slide quicker than usual, while a scale of (0.5, 0.2) will have it move instantly.
Increasing the scale difference drastically has the object teleport while not even close to the shape.
This happens if either the StaticBody object, the CollisionShape object, or a parent of the StaticBody object have uneven-scale.
An even scale like (0.5, 0.5) does not present this behavior.
Scaling the CharacterBody does not influence this in any way.
#### Context
I found this bug when one of the designers on my team wanted to make one of the levels slimmer so we scaled down the parent scene, and this affected all objects, and we couldn't replicate the bug in other scenes. I later found this bug when trying to make ellipsis colliders for props in a level.
The fact wild differences in scale have the character teleport while not even touching the shape has me think that the engine is using either the unscaled shape or only one of the scale coordinates to some of the calculations.
I suppose you're not intended to scale StaticBodies this way, but this not only limits what you can do with them (say, no Ellipsis shapes), but I also think it doesn't match expected behavior: if you scale a CharacterBody in a similar way, it slides as usual with no problems.
### Steps to reproduce
- Create a CharacterBody2D node (any motion mode)
- Make boilerplate movement code using ``move_and_slide()``
- Create a StaticBody2D with any CollisionShape with sides not aligned to the xy axis (like a rotated Rectangle, or Sphere)
- Scale either the StaticBody2D or the CollisionShape such that the X scale is not equal to the Y scale (click on Unlock Component Ratio)
- Run scene, try to walk over to the static body, the character should quickly slide to one particular edge and get stuck.
### Minimal reproduction project (MRP)
[CharacterBody2DSlideBug4.2.1.zip](https://github.com/godotengine/godot/files/14315343/CharacterBody2DSlideBug4.2.1.zip)
Contributor guide
Research direction
Start with the attached CharacterBody2DSlideBug4.2.1.zip and reproduce the issue using move_and_slide() against an unevenly scaled, angled StaticBody2D or CollisionShape. Investigate the CharacterBody2D sliding behavior and verify that non-uniform scale no longer causes accelerated sliding, sticking, or teleporting.
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
- 35/100