Weird behaviour of Area2D as a child node of a moving object

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By CharlyDelta
:warning: Old Version Published before Godot 3 was released.

Overview

In my 2D (top-down perspective) project I have a ship and the player is a crewman. He can walk around on the ship, and he can get into the cockpit and man it.

  • The ship is a KinematicBody2D and is moved using move
  • The player is a KinematicBody2D and a child node of the ship
  • To see if the player is in the cockpit, I spanned an Area2D inside it (this area is a child node of the ship as well). If the player enters it, and presses F, he mans it. Pressing F again will make the player leave the cockpit
  • I use the on_body_enter signal to set a variable at the player. If the variable is not null, he can enter the cockpit (the variable holds a reference to the cockpit. Later, he should be able to get into other positions as well, that’s the reason for this design)

The Problem

  • If the ship is static, i.e. its velocity is zero, there is no problem at all
  • If the player jumps into the cockpit and accelerates (forward), and leaves the cockpit, he cannot enter the cockpit again

Insights

  • At first, it seemed like the Area2D disappeared. I then created outputs in on_body_enter (“enter”) and in on_body_exit (“exit”)
  • On a static ship, when walking into the cockpit, “enter” was printed as expected. When leaving the cockpit, “exit” was printed. So far, so good
  • When accelerating, at first nothing happend. But then suddenly “exit” and “enter” spammed for a while and stopped again, always with “exit” (If i kept accelerating)
  • I jumped out of the cockpit at a certain velocity and walked around. I then noticed, that when I walk outside the ship (didn’t implement the walls yet), the “enter” output will show up. So the Area2D obviously floats a certain distance in front of the ship. When flying backwards, the Area2D will move inside the ship. This is true no matter into which direction the ship is flying (when viewed on a global coordinate system. It just depends on whether the ship is flying backwards of forwards)

SUMMARY

  • The bigger the velocity, the bigger the offset of where the Area2D should be located, and where it actually is. Note that with a constant velocity, this offset will remain constant as well
  • The offset will always be in flight direction. So if the ship is flying forwards, the actual hitbox will be in front of the ship, if flying backwards it will be inside the ship
  • If the player is very close to the area, it spams “exit” and “enter”, probably because of numeric inaccuracies
  • Printing the actual positions of the Area2D or the collision shape does not change at all. An sprite attached to it will not move as well. So it seems to stay static, but the collision detection obviously introduces an offset proportional to the velocity

Is this a bug, numeric inaccuracies, or are those some strange relativistic effects? Is this known? If so, what can I do?


Updates

  • Tried to move the updates of the position of both the ship and the player into _fixed_process rather than _process. I feel like I now have less “spamming”, but the described problem still persists
  • I had discussions on Godot’s Discord: I was asked if the collision areas were scaled, and indeed, they were. But changing the scale to (1, 1) did not solve the problem
  • After the Discord discussions, we came to the conclusion that it might be a bug. I created a small demonstration of the problem and created an issue on Godot’s issue tracker