You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Godot中为Transform3D的basis赋值Quaternion时出现无效赋值错误及相关问题求助

Godot中为Transform3D的basis赋值Quaternion时出现无效赋值错误及相关问题求助

我在Godot里运行下面的函数时,遇到了错误:"Invalid assignment of key or property 'basis' with a value of type 'Quaternion' on a base object of type 'Transform3D'."

func _orient_character_to_direction(direction: Vector3, delta: float) -> void:
    var left_axis = -local_gravity.cross(direction)
    var rotation_basis := Basis(left_axis, -local_gravity, direction).orthonormalized()
    _model.transform.basis = _model.transform.basis.get_rotation_quaternion().slerp(rotation_basis, delta * rotation_speed)

我跟着一个针对旧版Godot的教程学习,有些内容没法直接照搬,但我搞不懂为什么会出现这个错误,也没看到其他人遇到类似问题。

更让我困惑的是,明明代码是GDScript,却又弹出了这个错误:

E 0:00:00:0458 testplayer.gd:50 @ _orient_character_to_direction(): Basis [X: (0, 0, 0), Y: (0, 0, 0), Z: (0, 0, 0)] must be normalized in order to be casted to a Quaternion. Use get_rotation_quaternion() or call orthonormalized() if the Basis contains linearly independent vectors.
<C++ Error> Condition "!is_rotation()" is true. Returning: Quaternion()
<C++ Source> core/math/basis.cpp:725 @ get_quaternion()
testplayer.gd:50 @ _orient_character_to_direction()
testplayer.gd:25 @ _integrate_forces()

根据这个错误提示,我尝试在_model.transform.basis = _model.transform.basis.get_rotation_quaternion().slerp(rotation_basis, delta * rotation_speed)这条赋值语句的两端调用orthonormalized(),但要么是调用无效(在四元数之后调用),要么就是调用了也没用,错误依然存在——我几乎试了所有可能的位置,哪怕有些地方逻辑上根本说不通。我还试过对四元数调用normalized(),但完全没用。

我数学不太好,这也是我第一次用四元数,如果这是个很低级的错误,还请见谅。

备注:内容来源于stack exchange,提问作者VR Ro

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.04.15 09:42:58