Hello everyone, I'm working on enhancing character movement in my isometric game and need some help. Currently, my script supports basic directional movement (right, left, down, up, and diagonals like down-right, up-right, etc.). However, I want to upgrade this to support smooth movement across 16 precise directions (0°, 22°, 45°, 67°, 90°, 112°, 135°, 157°, 180°, 202°, 225°, 247°, 270°, 292°, 315°, 337°). This will allow me to match the character's movement more accurately with corresponding sprites for each direction. Does anyone have advice or examples on how to implement this finer directional control in Godot? Here's my current script that identifies the basic eight directions. Any guidance on refining it to handle 16 directions smoothly would be greatly appreciated!
extends CharacterBody2D
const SPEED = 3000
func _physics_process(delta):
var direction = Input.get_vector("ui_left", "ui_right", "ui_up", "ui_down")
if direction:
self.velocity = direction * SPEED * delta
else:
self.velocity = Vector2.ZERO
if vel == Vector2.ZERO:
print("Character is stationary")
else:
if vel.x > 0 and vel.y == 0:
print("Moving right")
elif vel.x < 0 and vel.y == 0:
print("Moving left")
elif vel.y > 0 and vel.x == 0:
print("Moving down")
elif vel.y < 0 and vel.x == 0:
print("Moving up")
elif vel.x > 0 and vel.y > 0:
print("Moving down-right")
elif vel.x > 0 and vel.y < 0:
print("Moving up-right")
elif vel.x < 0 and vel.y > 0:
print("Moving down-left")
elif vel.x < 0 and vel.y < 0:
print("Moving up-left")