+2 votes

I tried to follow this thread, but I keep getting errors. I thought it'd be best just to ask for an updated answer. This is what I tried, but I don't know how to parse the variable to only get a Vector3().

var rot = (get_parent().look_at((PlayerP.global_transform.origin),Vector3(0,1,0)))
looking.interpolate_property(PlayerP,"rotation",rotation,rot,.3,Tween.TRANS_LINEAR,Tween.EASE_IN)
in Engine by (293 points)
edited by

I don't think the answer has changed since. There are multiple ways of tweening a rotation, so you can't expect it to work the way you want by just directly tweening rotation. I would either tween the target position instead and look at it each frame, or tween an intermediary Basis or Quat custom property to avoid gimbal lock.

If you get errors, it would help to share them.

I'm just still new to this so, I don't really know what the syntax is needed to tween the rotation via basis. I don't know how to call it. An example would help.

The variable I made above returns a null, so I can't parse the transformation information I could use as the final value for the tween.

The error I'm getting is pretty much telling me the initial value doesn't match the final value.

look_at does not return anything. It only tells the node to look at a 3D point.
Try this instead:

get_parent().look_at(PlayerP.global_transform.origin, Vector3(0,1,0))
var rot = get_parent().global_rotation

Then, the tween you wrote will animate the rotation of the player to end up the same as whatever the get_parent() node is.

Thank you for the suggestion.

Is this syntax to tween a rotation correct for basis?

tween.interpolate_property(node,"rotation",mynode.transform.basis,othernode.global_transform.basis,.3,Tween.TRANS_LINEAR,Tween.EASE_IN)

No, because rotation is not a Basis, it's a Vector3.

This would run fine:

tween.interpolate_property(self, "rotation", mynode.rotation, othernode.rotation, 0.3, Tween.TRANS_LINEAR, Tween.EASE_IN)
tween.start()

I'm just a bit skeptical about the wrapping cases, for example, if your Y rotation is 175, and you want to look at -175, Tween is going to make the node rotate all the way around rather than going the shortest route (because angles can wrap!). If you end up with this problem, you will need Basis or Quat.
After asking Reduz (cuz there is no doc about this), the proper syntax to interpolate transform.basis is this:

tween.interpolate_property(self, "transform:basis", mynode.transform.basis, othernode.transform.basis, 0.3, Tween.TRANS_LINEAR, Tween.EASE_IN)
tween.start()

And still, this only covers the rotation tween itself. If the source of your initial and final rotations are for "looking at node A, then at node B" there is some math involved to obtain the rotations you need, which I think you did by calling look_at, getting the result, then changing rotation again through the tween.

Thank you for the comprehensive response. I'll be applying what you've taught me later after some thought. I'm still intimidate by the set/get variable, but I'll see what I can pull off.

Read my previous comment, I actually edited it later. You don't need set/get ;)

Awesome, thank you. That syntax was exactly what I was looking for. I now made a dummy spatial that's where I need it and have the tween copying the transform.basis. I appreciate you looking into this with your friend. If I could give you 'best answer' through comments I would!

One last question: What is the difference between rotation and rotation_degrees? in the script.

rotation_degrees is the same meaning as rotation, except it's degrees. rotation is in radians.
I added my relevant solution as answer.

1 Answer

+2 votes
Best answer

This would run fine:

tween.interpolate_property(self, "rotation", mynode.rotation, othernode.rotation, 0.3, Tween.TRANS_LINEAR, Tween.EASE_IN)
tween.start()

However it doesn't handle wrapping cases, for example, if your Y rotation is 175, and you want to look at -175, Tween is going to make the node rotate all the way around rather than going the shortest route (because angles can wrap!). If you end up with this problem, you will need Basis or Quat.

After asking Reduz (cuz there is no doc about this), the proper syntax to interpolate transform.basis is this:

tween.interpolate_property(self, "transform:basis", mynode.transform.basis, othernode.transform.basis, 0.3, Tween.TRANS_LINEAR, Tween.EASE_IN)
tween.start()

This only covers the rotation tween itself. If the source of your initial and final rotations are for "looking at node A, then at node B" there is some math involved to obtain the rotations you need, which you did by calling look_at, getting the result, then changing rotation again through the tween.

by (27,595 points)
selected by

Thanks again!

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.