Detecting KinematicBody2D collisions during tweens

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

I am scaling a node containing a KinematicBody2D, a Sprite, and a CollisionShape2D (rectangle) and trying to detect when this collides with another KinematicBody2D or StaticBody2D.

I have another KinematicBody2D ball bouncing around the scene, and it can interact with these nodes while they are scaling. It bounces correctly off of them both while the tween is going on, and when it stops. My problem is that I want to stop the tween when these nodes come in contact with each other, and I’m struggling to detect that collision.

I drop several of these nodes on top of each other, or have them intersecting and print(is_colliding()) is always false.

In this screenshot, the vertical and horizontal lines are these nodes. The ball is successfully trapped, and bouncing around in that little box in the lower portion of the screen.

If I press the button, a new node will be placed at the top of the screen, just above the arrow and start scaling downward. I’d like to detect, and stop this scaling it when it hits the top horizontal line, but I’m having difficulty detecting that collision.

All of these nodes are layer 1 with a mask of 1, while the ball is on layer 2 with a mask of 1 and 2

:bust_in_silhouette: Reply From: YeOldeDM
  1. Never scale physics bodies (including KinematicBody) or collisionshapes. You can change the shape (width/height) of a collisionshape, but its scale should always be 1 1.

  2. KinematicBody.is_colliding() will only return true if it’s colliding while in motion using move() or similar. More than likely though, you don’t actually need collision in your situation, only hit detection.