Hello everyone,
I recently converted my project to Godot 4 and all went great, until I encountered this issue. The problem is that, when RigidBody enters an area with gravity space override, gets pulled to the middle (gravity point enabled), then its position is set to the outside of this area, it is then still attracted by the area's gravity no matter where it is located. In Godot 3, this worked well. I have tried various solutions and workarounds, that I could come up with, but unfortunately nothing seems to work. I made two sample projects (one in Godot 3 and the other in Godot 4) to showcase this behavior. I am not quite sure if this could be some bug in physics engine in Godot 4 or it is just me doing something wrong. Any help is greatly appreciated. Thank you very much.

Project settings:
Default gravity vector: 0,0,0
Default linear damp: 0
Default angular damp: 0

Godot 4 code:

extends Node3D


func _physics_process(delta):
	if Input.is_action_just_pressed("ui_accept"):
		get_node("RigidBody3D").apply_impulse(Vector3(0,0,-1) * 100)


func _on_center_area_body_entered(body):
	body.freeze = true
	_reset_body()


func _reset_body():
	get_node("RigidBody3D").global_transform.origin = Vector3(0,0,60)
	get_node("RigidBody3D").freeze = false
`

Godot 3 code:
`extends Spatial


func _physics_process(delta):
	if Input.is_action_just_pressed("ui_accept"):
		get_node("RigidBody").apply_impulse(Vector3(),Vector3(0,0,-1) * 40)

func _on_Center_area_body_entered(body):
	body.mode = RigidBody.MODE_STATIC
	_reset_body()


func _reset_body():
	get_node("RigidBody").global_transform.origin = Vector3(0,0,60)
	get_node("RigidBody").mode = RigidBody.MODE_RIGID



area-gravity-samples.zip
5MB
  • xyz replied to this.
  • Lubix Definitely report it.

    As for workaround, try to make a duplicate of the rigid body node and delete the old one. Maybe that would reset it.

    Lubix Not sure 100% but this could be a bug. Godot 4 rigid body seems to forget to nullify area's gravity when manually plucked out of the area.

      xyz I think so too. The question is how to reset RigidBody's collision, so it is not pulled by area's gravity anymore? I have tried disabling and enabling collision layer and mask (both at RigidBody's side and area's), but this did not do anything. I have also tried to enable sleeping state and gravity did stop pulling RigidBody, but after reenabling the pulling was back. The other thing that I tried was setting gravity scale to 0 and then back to 1, but situation was the same as with sleeping state. As you can see from code, freezing the RigidBody (static mode) and unfreezing did not help either. I don't think there are many options left, but of course I could be wrong. Should I maybe report this as a bug?

      • xyz replied to this.
        • Edited
        • Best Answerset by Lubix

        Lubix Definitely report it.

        As for workaround, try to make a duplicate of the rigid body node and delete the old one. Maybe that would reset it.