Skip to content

Different output from Vector3::rotated in godot-rust vs GDScript #751

@robmikh

Description

@robmikh

I'm following along with this tutorial while porting the GDScript code to Rust. I ran into a difference in the output of Vector3's rotated function between Rust and GDScript.

I think it stems from a difference in how Godot and godot-rust handle the multiplication of a Basis with a Vector3:
https://github.com/godot-rust/godot-rust/blob/0413391002a1e824a36a7b012ce45774204eae3b/gdnative-core/src/core_types/geom/basis.rs#L585-L592
vs
https://github.com/godotengine/godot/blob/12e0f10c74e9619262f1edcfdc1840432ada0565/core/math/basis.h#L313-L318

I was able to resolve my issue by changing the implementation to match Godot's:

impl Mul<Vector3> for Basis {
    type Output = Vector3;

    #[inline]
    fn mul(self, rhs: Self::Output) -> Self::Output {
        Self::Output::new(
            self.elements[0].dot(rhs), 
            self.elements[1].dot(rhs), 
            self.elements[2].dot(rhs)
        )
    }
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugc: coreComponent: core (mod core_types, object, log, init, ...)help wanted

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions