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.