Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Bullet] Bullet physics: scaled collision shapes return incorrect normals #30214

Open
Tracked by #45022
TwistedTwigleg opened this issue Jun 30, 2019 · 5 comments
Open
Tracked by #45022

Comments

@TwistedTwigleg
Copy link
Contributor

TwistedTwigleg commented Jun 30, 2019

Godot version:
Godot 3.1.1 and Godot 3.2.dev.b4aba3ae7

OS/device including version:
Windows 10 64bit, Nvidia 660 TI

Issue description:
Bullet physics doesn't seem to take the scale of the collision shape into account when returning the normal vector from a Raycast, though the position returned is accurate. GodotPhysics does not have this issue.

While working on my painting system, I discovered that angled surfaces, like ramps, were not returning the correct normal vectors when using a raycast.

After many hours of debugging, I found that for a 45 degree surface, the raycast returned was off by roughly 4 degrees. For other angles, the offset is less, but still there. The raycast would not return accurate normal vectors for angular surfaces, it was always off at least by a couple degrees. For my paint system, the decal-like shader I am using requires fairly precise angles, so this issue made it nearly impossible to paint on angled surfaces.

I should note that the issue is only present in angled collision meshes. A rotated cube, for example, does not have this issue.

After lots of investigating, trying to write code to compensate, and more, I discovered the source of the issue: The MeshInstance nodes I was using for the ramp were scaled. For whatever reason, the scale of the MeshInstance node was messing up the normal vector returned by the raycast, despite everything else physics related, including the returned raycast position, works fine.

On a whim, I decided to see if the issue is present in both Bullet and GodotPhysics. Surprisingly, GodotPhysics does not have this issue, it returns the correct normal vector regardless of the scale, which is what I would expect and my project works like normal.

This leads me to believe the issue is somewhere with Bullet. I would expect the normal vector returned by the raycast to account for the scale of the collision shape when returning the normal vector.

I can attempt to help fix this issue, but I know little about Bullet/Game-Physics, so I have no idea where to look or what in the code base could be causing the issue.

Steps to reproduce:

For the sample project, try the following with both Bullet physics and Godot physics:

  • Run the project and face one of the colored ramps.
  • Hold the left mouse button with the center of the screen over a ramp.
  • Observe the angle of the light blue quad.
    • With Bullet physics, the light blue quad will show the normal returned as expected with the green colored ramps, however the purple colored ramps will return an incorrect normal, with the angle several degrees off.
    • With Godot physics, the light blue quad will show the normal returned is as expected regardless of the color of the ramp in use.

Minimal reproduction project:
Godot_Scaled_Physics_Shape_Example.zip

@TwistedTwigleg TwistedTwigleg changed the title Bullet physics scaled collision shapes return incorrect normals Bullet physics: scaled collision shapes return incorrect normals Jun 30, 2019
@Zylann
Copy link
Contributor

Zylann commented Jun 30, 2019

I think Bullet does not support non-uniformly-scaled collision shapes.

@TwistedTwigleg
Copy link
Contributor Author

Thanks @Zylann! That was the issue. It works fine when using a uniform scale.

Since that fixed the issue, should I keep this issue open and rename it accordingly or just close it?

@fracteed
Copy link

fracteed commented Jul 1, 2019

Oh, yeah there was definitely a change between 3.1.1 and current master in relation to this. I was somewhat shocked to find that my game was totally broken when trying it last week in current master.

I quickly discovered that any scaling(non-uniform of not) of a collision shape would cause problems. Was just a matter of setting every collision shape in my game to 1,1,1 scale and just adjusting the collision shape dimensions directly. This should be documented as a breaking change for 3.2, as no doubt many users will encounter it.

@jonri
Copy link
Contributor

jonri commented Jul 1, 2019

@fracteed sounds like you hit the issue I did: #29906
The fix got merged last week, so your master might have been built right before it. I think it's separate from the OP's issue since his also happens in 3.1.1.

@fracteed
Copy link

fracteed commented Jul 2, 2019

@jonri ah, thanks for the info! Still seems like a good idea that not have any scaling info on collision shapes, so I am glad I at least changed them all.

@pouleyKetchoupp pouleyKetchoupp changed the title Bullet physics: scaled collision shapes return incorrect normals [Bullet] Bullet physics: scaled collision shapes return incorrect normals Jan 15, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

5 participants