|Attention||Topic was automatically imported from the old Question2Answer platform.|
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 enemy.gd):
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?
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.