0 votes

I'm diving into the tests world in godot and everything is so far so good. But I have a question.

When I need to test somethings that uses physics I usually do the following steps:
1. Setup tests
2. Wait for simulation
3. Check results

An example:

func test_get_interaction_area_bodies():
  # SETUP
  # This is just a method to create a cube and add collisions based on the masks and layers
  var wall = TestUtils.create_static_body_cube(Vector3(0, 0, -1.5), [], [0])    
  # This is just a method to add child and free it on the end of the test
  self.add_child_autofree(wall) 

  # WAIT
  # This is what is confusing me
  yield(get_tree(), "physics_frame")

  # CHECK
  var bodies := main_player.get_interaction_area_bodies() # calls area.get_overlapping_bodies()
  assert_that(bodies).is_not_null().is_not_empty()

My questions is just on the "wait for simulation" step, because I didn't understood well how godot handle physics simulation. I know it have a PhysicsServer and every X ms it runs the physics step, before the broad phase and narrow phase and so on. But, if that was the case, just waiting for the next "physics_frame" should be enough to handle all collision detection, since I'm not moving anything, just placing them and checking of overlaps.

The problem is, some times I need to chain the yield 2, 3 or even 5 times in order to the simulation actually happens. The above example won't work, I need to change the waiting step to:

  yield(get_tree(), "physics_frame")
  yield(get_tree(), "physics_frame")
  yield(get_tree(), "physics_frame")

Anyone knows why I have to wait for 3 or more physics frames in order to a single overlapping bodies simulation happens?

Godot version 3.3-rc6
in Engine by (30 points)

Please log in or register to answer this question.

Welcome to Godot Engine Q&A, where you can ask questions and receive answers from other members of the community.

Please make sure to read How to use this Q&A? before posting your first questions.
Social login is currently unavailable. If you've previously logged in with a Facebook or GitHub account, use the I forgot my password link in the login box to set a password for your account. If you still can't access your account, send an email to webmaster@godotengine.org with your username.