This site is currently in read-only mode during migration to a new platform.
You cannot post questions, answers or comments, as they would be lost during the migration otherwise.
0 votes

I have a basic NPC with aim offset animations and forward spatial node for aiming.
The spatial node is tracking a player with look_at function. How do I match aiming blends with the rotation of the forward spatial node? Do I even need this extra node?

Here's my code:

forward.look_at(player.global_transform.origin, Vector3.UP)
var forward_facing = forward.transform.basis.z
animation_tree["parameters/fire/aim_x/blend_amount"] = forward_facing.x
animation_tree["parameters/fire/aim_y/blend_amount"] = forward_facing.y

The Y axis works (for example when I jump NPC is looking up as it should), but X is all over the place. X value should somehow change with the global position in the world. Aiming blends are simple Blend3 nodes with ranges going from -1 to 1.

Here's an image, basically a red arrow – where it aims, a blue arrow – where it should aim (an invisible forward spatial node looks at player, as it should).

aim offset

Thanks!

in Engine by (81 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 Frequently asked questions and 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 [email protected] with your username.