Get_overlapping_bodies() isnt working in the while loop

Godot Version

Godot 4

Question

get_overlapping_bodies() isn’t working in the while loop. This script is in an area 3d and I’m trying to move it down to the ground until it touches the ground. The only problem is it never touches the ground and only goes the maximum 200 units. you may be asking, “Why not use a raycast shape”. I cant because i want the raycst to grow as it moves out

func _physics_process(delta):
	var castLength = 0
	global_position = PlayerNode.global_position
	while get_overlapping_bodies().size() == 0 && castLength < 200:
		castLength += 1
		global_position.y -= 0.1

Physics are evaluated only once per frame. You can move a physics body 1000 times in different directions, but collisions will be reported only on the next _physics_process() call, not in the current frame.

1 Like

i have been struggleing for ages thankyou

is there anyway to acomplish what im trying to do?

Use raycasts (via a node or via the server).

Raycast node has force_raycast_update() function that can update physics as many times per frame as you want.

If using PhysicsServer for raycasts, you can cast as many raycasts as you need in the same physics frame.

But since you can’t use raycasts for some unspecified reasons, I don’t know any other way.

i need to change the raycast size per distance like this

 global_position = playerPos
while not_touching_anything():
     global_position.y -= 1
     raycastSize += 1