Is KinematicBody2D only for player scenes?

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

In the documentation for KinematicBody2D, it says:

Kinematic bodies are special types of bodies that are meant to be user-controlled.

Which gave me pause when considering how to implement some characters in my game! I currently have a player character scene with a KinematicBody2D root node and was considering having a base “character” scene for all characters to inherit from (including the player character), to handle general path-finding movement (player character movement is primarily point and click right now, where there are several obstacles like counters, etc, to navigate around given a Navigation2D and a corresponding tile map. Actual movement done via move_and_slide right now).

The other characters in my game would mostly be customers of the simulated store that would likely path find to a designated waiting area, then leave and path find out once they are given their order by the player character.

With my initial thought of just having the same movement functions for the player and customer characters, the customer characters would inherit from the generic “character” scene and script and have that same KinematicBody2D root node, then further have something like an Area2D child node in order to detect player clicks / interaction (all other interactables have an Area2D base node).

Can someone elaborate more on the documentation and when to use KinematicBody2D? Would this specific use case make sense, or is there a better/simpler way?

:bust_in_silhouette: Reply From: kidscancode

When it says “user-controlled” it’s talking about the programmer, not the player of the game.

Kinematic bodies are controlled by code you write. They do not move unless moved with one of the movement methods. This is in contrast to rigid bodies, which are controlled directly by the physics engine, which calculates their movement.

Your idea is perfectly reasonable. The only difference between the player and the customers is what determines their desired movement direction: input (for the player) or nav (for the customers).

Thanks so much for the quick answer! That helps a ton and gets me over my mental block. (also love your content! I’ve gone through a fair number of recipes and YouTube videos of yours :D)

patrice | 2020-06-05 23:27