3D collision detection - is this the correct way ?

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By GameVisitor

Hi all,

I am building a simple demo made of 2 scenes:

  • main scene containing the floors
  • cube scene

Upon loading the main scene, i am generating some cubes at random position.

collision code snippet:

set_physics_process( true )
set_max_contacts_reported( 1 )


	var bodies = get_colliding_bodies()
	for curBody in bodies:
		print( "collision :" + curBody.get_name() )

I am getting lots of prints and collisions, however:

  • Is this the correct way / “best performance” way of detecting collision in 3D ? I am asking this, cause having a simple scene with 40 cubes, makes the game “choke” for like 2 seconds.
  • Some collisions seems to pass undetected (even though CCD is enabled).

Btw, I am using Godot 3.0.5

Did you leave your print during the 40 cubes test? Printing is an expensive operation, so it should not be used to logspam.
Also, collisions can go undetected because you did set_max_contacts_reported( 1 ).

Zylann | 2018-07-23 12:51

:bust_in_silhouette: Reply From: GameVisitor

I did solve it, i was changing the cubes texture upon hitting certain body and the texture was being null, probably similar to throwing an exception and rendering it white. Once the correct texture was set the 2 seconds delay disappeared.

I also did turn off print statements in 2 _physics_process() of the game, prior to your suggestion and that gained me around 3 FPS.

As for your final suggestion, I think you are right, but what is the recommended value here ? surely setting it too high will have a strong performance impact, no ?

Thanks for your time @Zylann :slight_smile: