The Godot Q&A is currently undergoing maintenance!

Your ability to ask and answer questions is temporarily disabled. You can browse existing threads in read-only mode.

We are working on bringing this community platform back to its full functionality, stay tuned for updates. | Twitter

0 votes

Hello. I have a Sprite3D set up with 8-way animations, using an animation tree to handle which way it should look at. It works right now when I have a static camera, it'll show the correct animation. I'm using the blend position parameter with a vector that holds my inputs, but when I'm idling in a scene with the camera rotating I'd like for it to reflect on my character as well.

    tree.set("parameters/Walk/blend_position", input_vector)
    tree.set("parameters/Attack/blend_position", input_vector)
    tree.set("parameters/Idle/blend_position", input_vector)

This is how it's set up on the code right now, what would need to change on the idle one for it to update according to the camera rotation? Any code example also appreciated.

Edit: Forgot to add the camera for my characters is handled by a spring arm node.

Godot version 3.5
in Engine by (47 points)

1 Answer

+1 vote

Here's my answer to somewhat similiar problem.

I'm no expert in 3D, but here's my 2 cents. First of all, I think the orientation of the camera shouldn't matter but the relative position of camera - even if a sprite comes towards you from your left side, it should show a forward sprite, not right sprite. Second thing I'd do is making this problem 2D by leaving y axis out of the equation.

Something like this (untested, sorry if it doesn't work as expected!):

var pos_2d = Vector2(global_transform.origin.x, global_transform.origin.z)
var camera_pos_2d = Vector2(camera.global_transform.origin.x, camera.global_transform.origin.z)
var camera_pos_2d_local = pos_2d - camera_pos_2d
var forward = global_transform.basis.z
var forward_2d = Vector2(forward.x, forward.z)
var angle = forward_2d.angle_to(camera_pos_2d_local)

Use this angle to determine actual sprite. Close to 0 should be forward, around PI backwards.

Unfortunately I didn't get confirmation did it work out in the end.

by (1,100 points)
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.