Hello. I'm a bit stuck with implementing character movement for my little project.
I want pretty much the same controls as in Overcooked game. When a player presses UP key, the game character moves up, when a player presses DOWN key – the character moves down the screen. And that is very easy to implement with global translation.
I can't handle the character rotation though. For example at some particular moment character looks down. At this moment player decides to send the character UP. At the very beginning of the movement, I want the character to rotate to direction of movement – UP.
And I want it to be a smooth transition.
I did some monstrous code which looks pretty much like this:
# Declare member variables here. Examples:
# var a = 2
# var b = "text"
var ROTATION_SPEED = 5
var MOVE_SPEED = 6
# Called when the node enters the scene tree for the first time.
var dx = 0
var dy = 0
dx += 1
dx -= 1
dy += 1
dy -= 1
var direction = Vector3(dx, 0, dy) * delta
translate(direction * MOVE_SPEED)
if dx != 0 or dy != 0:
var targetRot = 0
var currentRot = fposmod($Rotation.rotation.y, 2 * PI)
if currentRot > PI:
currentRot = - (2 * PI - currentRot)
if dx == 1:
targetRot = 0
if dx == -1:
targetRot = PI
if dy == 1:
targetRot = -PI/2
if dy == -1:
targetRot = PI/2
print(currentRot, ' -> ', targetRot)
if abs(targetRot - currentRot) > PI / 360:
var delRot = 1 if currentRot < targetRot else -1
var minRot = min(currentRot, targetRot)
var maxRot = max(currentRot, targetRot)
$Rotation.rotation.y = clamp(
currentRot + delta * delRot * ROTATION_SPEED,
I believe – there's a better and less buggy solution than mine.