Ok so i am making a top down 2d game where if you press up you move up and if you press down you move down and so on. This is my code.

extends KinematicBody2D

export (int) var speed = 200

var velocity = Vector2()

func get_input():
velocity = Vector2()
if Input.is_action_pressed("Right"):
velocity.x += 1
if Input.is_action_pressed("Left"):
velocity.x -= 1
if Input.is_action_pressed("Down"):
velocity.y += 1
if Input.is_action_pressed("Up"):
velocity.y -= 1
velocity = velocity.normalized() * speed

Does anybody have any way of making my character face the direction he moves?

Just ignore this comment i did something stupid and now i am editing it so no one else can know what stupid thing i did.

Welcome to the forums @NboyYT!

You can make your character face the velocity using atan2, which converts a Vector2 to an angle:

rotation = atan2(velocity.y, velocity.x)

@Megalomaniak said: Merged duplicate topics. Sorry about that i was just making sure my post was in the right tag

@TwistedTwigleg said: Welcome to the forums @NboyYT!

You can make your character face the velocity using atan2, which converts a Vector2 to an angle:

rotation = atan2(velocity.y, velocity.x)

Hey thanks for your help

2 years later