Hello! I am making a 2D game and I have an entity on which I have a Velocity component (a Vec2) and I want to increase the entity's velocity in the direction that the entity is facing. So to do that I get the entity's Quat rotation from its Transform and save it as forward and I have the velocity I want to add as velocity. In order to get my velocity in the same direction as the entity, I am trying to use p' = qpq⁻¹, which I found on wikipedia, here: https://en.wikipedia.org/wiki/Quaternions_and_spatial_rotation.
let rotated_vel = forward * velocity * forward.conjugate();
However, the following line of code doesn't compile because multiplying by quaternions is not implemented for vectors and as far as I'm aware quaternion multiplication is not commutative.
error[E0277]: cannot multiply `bevy::prelude::Vec3` by `bevy::prelude::Quat`
--> src\gameplay\shared.rs:212:54
|
212 | let rotated_vel = forward * velocity * forward.conjugate();
| ^ no implementation for `bevy::prelude::Vec3 * bevy::prelude::Quat`
|
= help: the trait `Mul<bevy::prelude::Quat>` is not implemented for `bevy::prelude::Vec3`
How should I get around this? Otherwise, is there a different way of achieving my original goal?