0 votes

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 blendposition 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 blendposition calculations are correct?

I've tried:

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

and

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.

Godot version 3.3.2
in Engine by (466 points)

Please log in or register to answer this question.

Welcome to Godot Engine Q&A, where you can ask questions and receive answers from other members of the community.

Please make sure to read How to use this Q&A? before posting your first questions.
Social login is currently unavailable. If you've previously logged in with a Facebook or GitHub account, use the I forgot my password link in the login box to set a password for your account. If you still can't access your account, send an email to webmaster@godotengine.org with your username.