2D Leg rotation via key input

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

I’m working on a soon to hopefully be zombie survival game… but I’m getting a weird glitch while trying to rotate the legs to face the direction of input (in a sum and total), so that the legs(sprite) seem like there facing towards the direction you’re walking…

I have this for my movement so far…

var velocity = Vector2()
var rotation_speed = 180
var rot_dir = 0

func _ready():
set_process(true)

func get_input():
rot_dir = 0
velocity = Vector2()
if Input.is_action_pressed(‘ui_right’):
velocity.x += 1
rotation += -90
if Input.is_action_pressed(‘ui_left’):
velocity.x -= 1
rotation += 90
if Input.is_action_pressed(‘ui_down’):
velocity.y += 1
if Input.is_action_pressed(‘ui_up’):
velocity.y -= 1
velocity = velocity.normalized() * speed

func _control(delta):
$Body.look_at(get_global_mouse_position())

func _physics_process(delta):
get_input()
move_and_slide(velocity)

the code in bold-italics is me attempting to get rotation to the legs(sprite) movement… but I see now that the glitch is probably my code attempting to rotate my whole kinematic-body and my body(sprite) is attempting to follow the mouse at the same time… so I suppose my new question is…
How would I move the legs of my character separately to the body with key input?
(while keeping my body and legs in place of the whole kin-body)
(I’ll figure that part out if I can manage to rotate sprite animation with key in put without it effecting my movement)