How do you rotate a KinematicBody2D?

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

I have a long thin KinematicBody2D (a character’s weapon) that I want to rotate by an amount or until it hits something. There doesn’t seem to be any rotational equivalent of move[_to] - am I missing something? Is rotating a KinematicBody2D just out of the question? I figure if I rotate it more directly, like just setting transform/rot, then it will break out of the expected physics constraints which I know causes horrifying side effects.

Worst case I could represent the weapon as a KinematicBody2D small circle representing the tip of the weapon, move that in a linear fashion corresponding to the desired rotation, and then rotate the sprite so its new angle positions the tip at that kinematically controlled point, but that’s really not the way I’d like to go. :frowning:

I have wondered the same at some point. I think my workaround was to rotate then move(Vector2(0, 0)) to stay in place but check for collisions. Probably not an ideal way…

Tegu | 2018-01-25 07:09

What kind of weapon? It appears that it doesnt need to be a kinematicbody. Maybe a simple sprite could do the trick, with an Area2D collision detect.

gtkampos | 2018-01-25 19:48

:bust_in_silhouette: Reply From: hilfazer

Animate.
Here’s GDquest’s tutorial for Godot 3 part one:

and two:

For stopping an animation there is AnimationPlayer.stop() method.