Isometric Movement Broke

Godot Version

Godot 4.6.

Question

Hi, I’m having a problem with my Player isometric movement code, and I’d really appreciate it if anyone could help me. Here’s the code:

class_name Player extends CharacterBody2D;

@export var limit_speed: float = 30.0;
@export var acceleration: float = 300.0;
@export var friction: float = 100.0;

var input: Vector2 = Vector2.ZERO;

func _physics_process(delta: float) → void:player_movement( delta );

#Pega os inputs do jogaodor.

func get_input() → Vector2:input = Input.get_vector(“move_left”, “move_right”, “move_up”, “move_down”);return input;



func player_movement(delta: float) → void:input = get_input();

## Verifica se o player parou de se mover, se parou aplica a friction para que a parada não seja automática.
if ( input == Vector2.ZERO ):
	if ( velocity.length() > ( friction * delta ) ):
		velocity -= velocity.normalized() * (friction  * delta);
	else:
		velocity = Vector2.ZERO;
# Se o player está se movmendo aplica a aceleração nele até chegar na velocidade máxima.
else:
	velocity += ( cartesian_to_isometric( input ).normalized() * acceleration * delta );
	velocity = velocity.limit_length( limit_speed );

move_and_slide();

func cartesian_to_isometric(cartesian: Vector2) → Vector2:return Vector2(cartesian.x - cartesian.y, (cartesian.x + cartesian.y) / 2 );

My problem is this: when I call the “move_up” input, it should go to x = -1 and y = -0.5, but it goes to x = 1 and y = -0.5. I’ve already tried reversing cartesian.x - cartesian.y to cartesian.x + cartesian.y, but when I do that, still breaks. Sorry for my English; it’s not my native language.

A few things:

  1. You don’t need semicolons in GDScript.
  2. Indentation is important in GDScript. Your player_movement_script is indented incorrectly.
  3. You should not combine Lambdas with normal code in the same function. Another reason your player_movement_script may not be working correctly.
  4. You are using a lot of Lambdas which provide no functional benefit. They just make your code harder to read and debug. Lambdas are typically used for Functional or Asynchronous programming paradigms. You are doing neither here.

Basically, if you formatted your code using the GDScript Style Guide, you would likely solve your problem. And if not, it would be a lot easier for more people to help you solve it. Because TBH, even though I can read it, you’re making me do extra work and it’s past midnight and I don’t want to.