How to use BlendSpace2D with an enemy node that moves on a path?

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By Macryc

Hi Guys. How do I use BelndSpace2D on a enemy node?

I’m working on a 3d FPS. My enemies are kinematic bodies moving and sliding along paths.

I’ve created a BelndSpace2D for the enemy node, with animations all around: forward, backward, sideways, diagonal.

I am currently using the enemy’s movement vector (calculated as the difference between its global transform and the next path point) as the indicator for the blend_position.

Current code (this is inside physics process in

move = mov_vec.normalized()
var blend_pos = Vector2(move.x, move.z*-1)

This works but only in global space. Once I rotate the enemy node towards the player, this all goes awry becasue the movement vector is in global space - so the enemy node faces the player but its animations are all wrong.

The QUESTION: For the blend_position calculation, and right before it, how do I rotate the movement vector of the enemy so that it matches its orientation in the world and the blend_position calculations are correct?

I’ve tried:

move = move_vec.rotated(Vector3.UP.normalized(), global_transform.basis.get_euler().y)


move = move_vec.rotated(Vector3.UP.normalized(), global_transform.basis.get_rotation_quat().y)

Neither of which worked - the enemy’s BlendSpace2D is still animating incorrectly.
I’m stuck. Please help.