How to convert information from Quaternion basis to rotation of my object?

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By Colossus3451

Hi. I am new with godot, but i wanna make something like steampunk skyships battle, and i need something like linear interpolation for rotation for more smoothly animation. I found that Quaternion have func slerp but i tottaly don’t understand how to convert information from Quat to my rotation. In unity the same functionality can be reached with someting like transform.rotation = originRot * rotY * rotX. So how in godot do something like this?

:bust_in_silhouette: Reply From: rakkarage
# Convert basis to quaternion, keep in mind scale is lost
var a = Quat(transform.basis)
var b = Quat(transform2.basis)
# Interpolate using spherical-linear interpolation (SLERP).
var c = a.slerp(b,0.5) # find halfway point between a and b
# Apply back
transform.basis = Basis(c)
1 Like

This answer just helped me out a lot! I’m working with godot 4.1, so in my context the “Quat” instead needed to be “Quaternion” and the transform.basis also needed to be “orthonormalized()” to prevent odd behaviors that I cannot fully describe. My version was the following:

# Convert basis to quaternion, keep in mind scale is lost
var a = Quaternion(nodeA.transform.basis.orthonormalized())
var b = Quaternion(nodeB.transform.basis.orthonormalized())
# Interpolate using spherical-linear interpolation (SLERP).
var c = a.slerp(b,0.5) # find halfway point between a and b
# Apply back
nodeA.transform.basis = Basis(c)
1 Like