Repository: godot
Issue: [2.1.4] Collision offset of Area2D when parent is in movement
Labels: bug,topic:core,confirmed

### **Operating system or device, Godot version, GPU Model and driver (if graphics related):**

- OS: *Ubuntu 17.04*
- Godot: *2.1.4*
- GPU: unrelated, but *GTX 860m* using the proprietary drivers

### **Issue description:**

**The scenario**

- I have a ship and a player (both `KinematicBody2D`)
- The player can freely move on the ship (player is a child node of ship)
- Ship has a cockpit, player should be able to enter the cockpit to fly the ship
- The cockpit is a `Area2D` to detect a collision (i.e. if the player inside the cockpit, so the 'Action' key triggers the 'player-enters-cockpit' action)

**The Problem:**

- In the beginning, ship and player are stationary. Player might move into the cockpit and enter it. Player may then accelerate the ship and jump out. Eventually, he might come back, but cannot enter the cockpit anymore because there is no collision detected by the `Area2D`
- Depending on the velocity of the ship, the actual collision area of the `Area2D` will move ahead of the ship. I.e. there is an offset (see illustration below)
- The higher the velocity, the higher the offset
- If the velocity is constant, the offset is constant as well
- The offset is *always* in the direction of flight. The rotation of the ship is irrelevant

Here's an illustration (desired/expected place of collision in a moving ship in red on the left, and the actual place of collision in red on the right):

![dfss](https://user-images.githubusercontent.com/13337480/31276076-514f40b4-aa9a-11e7-8721-193208908ade.png)

**Worth mentioning**

- If you enable <kbd>Visible Collision Shapes</kbd> in the debug tools, you won't see any offset at all. The shapes are obviously colliding
- I made a test and manually calculated the collision detection, which produces correct results (i.e. the collisions are detected right, regardless of what the velocity is). A bit more specific: if I check for collision using `collide()` of `RectangleShape2D` for the player model and the `Area2D` inside `_fixed_process()`, I get correct results. However, this is not really practical, since I need to know all possible collision objects in advance... I would expect, that the `body_enter` and `body_exit` events honour the `_fixed_process`-ing (i.e. that the calculations which lead to these events are synchronous with `_fixed_process`)

```gd
func _fixed_process(delta):
    # ...

    # Workarround
    var player = get_node('../path/to/player')
    var bb_player = player.get_node('collision-model').shape
    var cockpit = get_node('../path/to/cockpit/location')
    var bb_cockpit = cockpit.get_node('collision-model').shape
	
    if bb_player.collide(player.get_transform(), bb_cockpit, cockpit.get_transform()):
        print('collision')
    else:
        print('no collision')

    # ...
```

### **Steps to reproduce:**

- I made a small demonstration project [right here](https://github.com/charlydelta/godot-movement-cd-bug)
- You can only toggle between two velocities, but it shows the problem quite well I think
- Use <kbd>S</kbd> to travel at a slow velocity (i.e. the hit detection works)
- Use <kbd>F</kbd> to travel at a fast velocity (i.e. the hit detection wont work)
- You can observe the `body_enter` and `body_exit` events in the `print` output
- Traveling at slow speed should indicate `"ENTERED"` in the output. If you toggle to a fast speed, you should see, that the player left the cockpit according to the engine (indicated by `"LEFT"`)