How to change the calculation of one of the axis for a vector using .direction_to?

Godot Version

4.3

Question

I have this piece of code:

var direction = (global_position.direction_to(player.global_position)).normalized()

It’s used to calculate both movement vectors and blendspace2d directions.
I wanted to change the direction that blendspace2d sets without having to add another blendspace2d and setting up all the animations again.

Because of that I was wondering whether there is a way to set a vector - var direction - using .direction_to that would keep the y axis but set x = -x?

Can you make a new variable meeting these requirements?

var direction_x = Vector2(-direction.x, direction.y)
1 Like

Damn, it really was that simple… I got stuck trying to impliment more and more creative solutions xd

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.