How to make Area2D's gravity affect a KinematicBody2D?

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

I’m making an entity that pulls player closer to it if player gets too close.
The entity has Area2D with gravity properties. I read online that a KinematicBody2D can get affected by the Area2D point gravity but it must be implemented in the code.
How can I go about doing so?

As far as I know you can only do that with “Rigidbody”. (Not Kinematicbody)

ramazan | 2022-07-16 12:03

:bust_in_silhouette: Reply From: USBashka

KinematicBody movement controls entirely from code, so gravity effect won’t affect it.

You can:

  • Change type to RigidBody, but note that controllling code will be different
  • Add custom gravity vector to the body’s velocity in code

Thx, custom gravity vector worked well in my case!

Krasapan | 2022-07-23 14:38