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 think the physicsbodystate has a gravity variable.
It looks like state.total_gravity only has a getter. In any case, I was unable to change gravity through it.
I tried changing space manually via this method, but it had no effect:
It also seems that after teleportation, this area ceases to change the body gravity at all, even if the gravity was changed by another Area3D to the correct one.
There doesnāt seem to be an easy workaround here
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
Iāve been taking a poke around the physics engine.
I found a comment that breaths a lot of confidence in to Godotās physics
⦠The space3d is the component of the physics engine that tests for collisions. Iām trying to understand the flow of a body entering and exiting an area.
Iām also hitting this bug. For me the repro involves having a body enter a gravity override area3d, then setting the body kinematic / freezing it and moving it out of the area.
If you look at the total_gravity param, itās whatever the area3d set it to. Havenāt currently got a work around. Iāll post back if I find one.
Looking at the source, itās probably that the area still exists in the bodies area list, so calling remove_area with the related area in c++ would probably fix it.
Wow, I didnāt know that was already being fixed) Looks like this fix is āāin the current RC, so Iāll wait for the next release to fix this issue. Thanks to all