How to fix: Collision between 2 KinematicBodies changes by changing the movement speed

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By bastilo

I’m creating an endless runner. The player can move in a certain range that is determined by an invisible box. Both the player and the box are KinematicBodies. Here is how it looks in the example scene:

Scene Structure
Scene

The blue box is the player, the collision box before that belongs to the “Box” node. In this example, the box is constantly moving forward and the player is moving backwards (towards the box’s CollisionShape):

Code

The problem is that, if after a while I increase the speed of the box, the distance between the player and the box changes.

Low speed of the box:
Output 1

High speed of the box:
Output 2

Any guesses how to fix that?

:bust_in_silhouette: Reply From: imjp94

In order to let camera follow player, you can simply just attach Camera to it.

Here’s how your hierarchy should looks like:

  • Bug
    • Player
      • CollisionShape
      • MeshInstance
      • Camera
    • Timer

And _physics_process should be:

func _physics_process(delta)
    $Player.move_and_collide(Vector3(0.0, 0.0, 1.0) * delta)

Problem is that I want the player to move forwards and backwards, even sideways without the camera following. Imagine an endless runner but you can move within a certain area.

bastilo | 2020-04-03 09:45