How to get the local velocity of a rigidbody2d?

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

I want to make a little bot that follows the player around in space. So when the player moves away the bot tries to catch up again but when it moves sideways from its local position it just keeps on spinning around the player

:bust_in_silhouette: Reply From: SteveSmith

To get the velocity (and direction) it’s:-


Well thanks for the answer but i was looking for local velocity. I already know how to get a state of a body. Asking different now: How do i convert the linear velocity from a global viewpoint to the local viewpoint of the body corrolating to the rotation?

Creka | 2023-02-16 17:25

I must admit I didn’t think there was such a thing as “local” velocity. Could you subtract the velocity of the parent?

SteveSmith | 2023-02-16 19:26

Well well… i solved it. Using ChatGPT
It just spit out this code and its working as i intended :smiley:


Creka | 2023-02-17 00:15