• Godot Help
  • Rigidbody3D Sometimes Clip Into Surfaces

I have gun. Gun have two collision shapes for handle and barrel. The gun is using default RigidBody3D physics. No code.

I have level. StaticBody3D level made up of mesh and a very specifically designed collision shape (TBLoader Addon).

I have button that lets me "drop" the gun. It instantiates the gun as shown in the first screenshot with a random orientation and a set impulse + the player's velocity.

#Apply "throw" physics to WorldItem
var dir:Vector3 = -camera.get_global_transform().basis.z;
worlditem.rotation_degrees = Vector3(randi_range(0,359),randi_range(0,359),randi_range(0,359)); #random orientation
worlditem.position = camera.global_position + dir*0.2; #spawn a bit in front of camera (not enough to spawn in wall)
worlditem.throw((dir*6)+velocity); #does apply_central_impulse() somewhere else because i cant do it here for some reason

Sometimes it works as intended. Sometimes it clips through walls and sometimes through the floor.
I believe this is a product of the object moving too fast for it to be able to detect collisions properly, since I can reproduce the issue consistently by running towards a wall and dropping the gun.

What would be the most elegant way to fix the issue?

TL;DR Rigidbody3D moving really fast clips through StaticBody3D. Me no like. How fix?

  • Megalomaniak replied to this.
  • poombus What would be the most elegant way to fix the issue?

    Maybe try dampening or clamping the input velocity that goes into the throw method?

    poombus What would be the most elegant way to fix the issue?

    Maybe try dampening or clamping the input velocity that goes into the throw method?

      Megalomaniak Dampening does work in preventing any accidental cases, but actively trying to clip the object can still be done. And I'd like to avoid clamping velocity if possible.
      I'm open to more complex solutions.

      I wrote a script that points a raycast with the direction and magnitude of the RigidBody's linear velocity. When the raycast detects and object, it starts cutting it's linear velocity by 10% per frame. (Does this count as clamping?)

      It works alright (no clipping yet) and it's hardly noticeable. I wonder if it'll break at Mach speeds.

        I guess I ended up using clamping in the end. Just with extra steps. (Some hard-coded values need some tweaking.)

        poombus When the raycast detects and object, it starts cutting it's linear velocity by 10% per frame. (Does this count as clamping?)

        I'd call that dampening. Clamping would just cut values above a certain value. i.e. never letting the velocity be greater than value x. Dampening is an over time effect, lowering it over time.