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

PhysicsMaterial Bounce behaves random/broken when enabling continous Collision Detection for a RigidBody3D #69667

Open
michael-nischt opened this issue Dec 6, 2022 · 5 comments

Comments

@michael-nischt
Copy link

Godot version

v4.0.beta7.official [0bb1e89]

System information

Arch Linux, Nvidia 3080

Issue description

Probably since the collision detection divides the motion into multiple sub-steps but and the "bounce" is only based on the last instead of the total motion?

Steps to reproduce

Launch/play the attached project.

Hold SPACE until the ball slides down the Wall and does not bounce.

Observe that the ball's physical material has a bounce value of 0.5.

Change the BOUNCE constant in ball.gd to true:

const BOUNCE : bool = true

This will disable continuous_cd on the RigidBody3D.

Relaunch and hold SPACE to see the ball bounce properly.
(But will tunnel at higher speeds.)

Not that the force / distance / .. are chosen so that no bouncing happens with CD enabled. However, bounces can happen for other values. Probably dependent on the CD steps.

Minimal reproduction project

BounceBug3D.zip

@michael-nischt michael-nischt changed the title PhysicsMaterial Bounce beahves random/broken when enabling continous Collision Detection for a RigidBody3D PhysicsMaterial Bounce behaves random/broken when enabling continous Collision Detection for a RigidBody3D Dec 6, 2022
@DanilaMihailov
Copy link

Happens for me on v4.0.rc1.official [8843d9a]. I have simpler setup, just 2 balls with collision shape radius 0.1 and bounce 1, hovering above ground. One ball with CCD enabled, another one is not. When balls drop, ball with CCD enabled loses all momentum and jumps slightly on the ground. While ball without CCD jumps full height as expected.

One thing I found, is that increasing collision shape radius to 0.5 is enough for bounces work as expected. But I am trying to make a tennis ball :(

@Calinou
Copy link
Member

Calinou commented Feb 14, 2023

One thing I found, is that increasing collision shape radius to 0.5 is enough for bounces work as expected. But I am trying to make a tennis ball :(

You can probably make the floor collider thicker and disable CCD.

@DanilaMihailov
Copy link

One thing I found, is that increasing collision shape radius to 0.5 is enough for bounces work as expected. But I am trying to make a tennis ball :(

You can probably make the floor collider thicker and disable CCD.

It was the first thing I did, after learning about "small fast moving objects". Walls 2m thick helped, but ball still went through sometimes. For now I just use CharacterBody3D, apply gravity to it and calculate bounce with simple code from docs.

With my simplified implementation ball does not go through walls even at speeds 100 times faster, than I used with RigidBody without CCD. Which I don't understand why :)

@MasterEvilAce
Copy link

Still an issue with 4.0.1. CCD completely breaks physics. Doing an example project to learn Godot and ran into this issue.
RigidBody3D ball and StaticBody3D walls/windows. All objects have 0 gravity, 0 friction, 1.0 bounce.

I spawn a ball (sphere collision of 1m) and apply an impulse in a random direction.
With CCD on the ball either
A) completely stops on contact with a staticbody OR
B) loses around ~50% of its momentum on FIRST bounce. Subsequent bounces usually maintain momentum but randomly a bounce will lose even more momentum until the ball stops completely.

With CCD off, the ball works as expected except now it occasionally passes through a window because it's going so fast (which CCD is needed to fix.)

@ghost
Copy link

ghost commented Aug 28, 2023

I've been digging into this and it seems the core problem is with this part of solving for CCD

p_A->set_linear_velocity((mnormal * newlen) / p_step);

which actually has a comment above the method describing exactly this problem:

// Warning: the way velocity is adjusted down to cause a collision means the momentum will be weaker than it should for a bounce!

Basically it appears that, for CCD, Godot modifies the linear velocity so that the body arrives on the next step at the collision point, but that means that any collision response now sees an altered velocity. I'm trying some approaches of instead modifying the current position so that the body arrives at the collision point with the same velocity after the next step. Not sure if it's 100% the right fix, but going to see if I can get something working there.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants