Hello! I discovered a bug in Godot 4 related to gravity override. If position of the RigidBody3D changes (for example for teleportation), gravity will not be changed if the body was inside the Area3D. There is no such bug in Godot 3. I opened an issue about this, but no one has responded to it yet:
The error persists with any method of body teleportation. Initially I tried changing global_transform.origin, then state.transform in the _integrate_forces. I also tried freezing body while teleporting, but that doesn’t help.
It appears that the body is not being removed from overlapping bodies in PhysicsServer3D. Interestingly, when teleporting - _on_body_exited() is called, but gravity does not change to global gravity for some unknown reason.
I wouldn’t want to remove the body from the SceneTree as it would have a big impact on performance. Is there a way to “reload” the body so that it is definitely reinitialized in PhysicsServer3d? I would just call this every teleportation for the teleported body.
I wonder if there is some Area collision logic to change forces applied that the teleport bypasses. I’ll see if I have time to look at the Godot source code later.
This is just a hunch, but what if the forces like gravity are stored per physics object. If that total_gravity is a read only that gets modified by the Area on entry. We could undo it by applying a constant force to cancel area effects.
Although I don’t know what would get updated.
In order to calculate the force use the old physics formula F=m*a
This is pseudo code but I trust that the info is available some how
# undo area gravity before or after teleport (area on exit signal?)
var area_force_dir_vec = area.grav_dir_vec * ( body.mass * area.grav_acc)
body.apply_constant_force( -area_force_dir_vec )
This definitely works to cancel out the effects of gravity :3
It’s a pity that the constant forces option doesn’t quite suit me, it looked promising. I’m making a game with portals and changing gravity. I’m using the gravity vector to flip the character. If no workaround will be found/this bug will not be fixed, I will most likely have to make a complete copy of the existing gravity_override system based on changing global gravity or something similar.
In any case, thanks for your help . If no one paid attention to this the bug, I would go crazy