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] RayCast collision noise near edge of static body #49163

Open
Tracked by #45333
goatchurchprime opened this issue May 28, 2021 · 6 comments
Open
Tracked by #45333

[Bullet] RayCast collision noise near edge of static body #49163

goatchurchprime opened this issue May 28, 2021 · 6 comments

Comments

@goatchurchprime
Copy link

Godot version:
Godot 3.3.2-stable

OS/device including version:
Linux

Issue description:
A RayCast cursor from the player's hand is used to select and draw onto different surfaces flashes in and out of contact as they move the ray off the edge of the surface.

Peek 2021-05-28 11-31

The minimal reproduction project makes 0.1mm steps through a series of origin points for the RayCast and shows how the collider goes in and out of existence.

z=-24.545801 --> (12.104905, 0.000062, -25.103224)
z=-24.545702 --> (12.104907, 0.000009, -25.103149)
z=-24.545603 --> (12.104907, 0.000001, -25.103054)
z=-24.545504 --> (12.104905, 0.000084, -25.102917)
z=-24.545404 --> (0, 0, 0)
z=-24.545305 --> (12.104906, 0.000022, -25.102747)
z=-24.545206 --> (0, 0, 0)
z=-24.545107 --> (0, 0, 0)
z=-24.545008 --> (0, 0, 0)
z=-24.544909 --> (0, 0, 0)
z=-24.544809 --> (12.104907, 0.00002, -25.102251)
z=-24.54471 --> (12.104905, 0.000084, -25.102123)
z=-24.544611 --> (0, 0, 0)
z=-24.544512 --> (12.104907, 0.000001, -25.101965)
z=-24.544413 --> (12.104907, 0.00002, -25.101854)
z=-24.544313 --> (12.104908, -0.000001, -25.101765)
z=-24.544214 --> (12.104907, 0.000001, -25.101667)
z=-24.544115 --> (12.104906, 0.000012, -25.101562)
z=-24.544016 --> (0, 0, 0)
z=-24.543917 --> (12.104907, 0.000009, -25.101364)
z=-24.543818 --> (12.104907, 0.00002, -25.101259)
z=-24.543718 --> (0, 0, 0)
z=-24.543619 --> (0, 0, 0)
z=-24.54352 --> (0, 0, 0)
z=-24.543421 --> (0, 0, 0)
z=-24.543322 --> (12.104907, 0.00002, -25.100763)

Steps to reproduce:
The CollisionShape in the StaticBody is a (1,1,0.01) Box.

I scale the StaticBody by (25,25,1) to set it to the size I want it to be, because this is more convenient than having to set the Box size and the scale on the visible Mesh object individually. The StaticBody is where I can do both at once.

I suspect (but am not sure) my margin is somehow getting scaled by 25 up from 0.01 to 0.25 in the X and Y planes, and that the RayCast algorithm treats this as a tolerance value and considers it optional whether or not a RayCast passing outside the object but within the margin reports a collision.

To avoid this noise I would like to set this margin to 0.0, but this is not allowed. However, I could hack values below the minimum allowed by creating a large surface and scaling everything proportionally down -- if margins are being scaled.

But why would the CollisionShape margin being scaled at all, since its effects and use (for performance) take place in the global space?

Minimal reproduction project:
raycast_dither.zip

@Zireael07
Copy link
Contributor

AFAIK physics bodies should NOT be scaled EVER.

@Calinou
Copy link
Member

Calinou commented May 28, 2021

AFAIK physics bodies should NOT be scaled EVER.

Scaling collision shapes uniformly should be fine, but scaling non-uniformly is not.

So yes, you need to adjust the shape's extents instead of scaling it.

@Calinou Calinou changed the title RayCast collision noise near edge of static body [Bullet] RayCast collision noise near edge of static body Jan 18, 2022
@Calinou
Copy link
Member

Calinou commented Jan 18, 2022

@goatchurchprime Can you reproduce this on 3.4.2, with Bullet and GodotPhysics as the 3D physics engine?

@goatchurchprime
Copy link
Author

goatchurchprime commented Jan 26, 2022

I had to ask elsewhere about how to change the physics engine (it's in the editor settings).

The ray cast problem seems to be gone when I tested in my game. (I have not tested with the minimal reproduction project). As I said above, the issue is probably caused by scaling the margin when scaling the cuboid body. (This should be allowed since a scaled cuboid body is still a cuboid body, and it's a quick way of changing its dimensions at the same time as the visible mesh object it represents.)

However, I encountered other dithering issues to do with my KineticBody that I will have to investigate when I switch engine.

tunnelvr_v0.7.DEBUG.2022-01-26.13-44-18.mp4

I also tried out my standard test of throwing out 50 boulder shaped objects and letting them fall as PhysicBodies and found that GodotPhysics reduced to a frame rate down to 1 per second (there is no frame rate drop with BulletPhysics). I am hoping this is because GodotPhysics has not been (prematurely) optimized.

@Calinou
Copy link
Member

Calinou commented Jan 26, 2022

I had to ask elsewhere about how to change the physics engine (it's in the editor settings).

The physics engine is configured in the project settings, not the editor settings 🙂

PS: You need to add a line break before and after video URLs to enable inline previews. I edited your comment accordingly, but remember to do this in the future.

@tvardero
Copy link

tvardero commented Apr 16, 2022

Collision noise near edges is still here on Bullet engine, but not on GodotPhysics engine.
Godot 3.4.4 stable mono, Win10 x64

2022-04-16.21-03-41.mp4

RayCast is being cast from the middle of the head, behind the player to make 3rd person camera collisions with terrain and objects.
RayCast detects collisions where no collision shapes are to collide with:

2022-04-16.21-10-05.mp4

I thought that Bullet engine might account player movements to 'predict' future collision. Unfortunately, collision noise appears even when player is neither moving (seen in first video at 0:30 - 0:32) nor rotating camera.

Repo: https://github.com/tvardero/void_3

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

4 participants