0 votes

Hi Guys. In a 3rd person game I want my character's top to look at the camera raycast's collision point so that the character aims towards the the target that the camera is facing. I've got the skeleton all set up and it's working using look_at_from_position.

When the raycast hits a collider that is closer to the camera, the top part of the skeleton abruptly changes its direction to face the new collision point.

The direction is correct but I'd like to smoothen those abrupt changes. I've experimented with looking_at (interpolating the direction, with the target direction being a sum of the character's spine bone IK transform and the target's transform) which kind of does what I want but it's imprecise (ie, it yields different direction results than look_at_from_position).

Is there another way to smoothen look_at_from_position?

Godot version 3.2
in Engine by (506 points)

1 Answer

0 votes

I once dug into look_at_from_position().
static func set_direction(spatial: Spatial, direction: Vector3):
. #Reference: Godot source code
. #Reference: MESA source code
. var z := (-direction).normalized()
. var x := Vector3.UP.cross(z)
. var y := z.cross(x) #assert(x.length())
. x = x.normalized()
. y = y.normalized()
. spatial.transform.basis = Basis(x, y, z)

I translated and tweaked the function, but it should give you the value you seek. To get "direction", just subtract your top position from the collision's. To animate, you can use a Tween.

by (2,634 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.