I want to rotate my object by a given amount and translate it forward to create a steerable tank.
I couldn't find out how to do it, all the matrices, vectors, and quaternions make it difficult for me to find a solution.
This is the Unity equivalent of what i want to do:
transform.Rotate(0, 0, -turn_input * turnSpeed * Time.deltaTime);
transform.position += transform.forward * drive * speed * Time.deltaTime;
I used to use this code in Bevy 0.2.1 but it broke after updating to 0.4
*transform.value_mut() = *transform.value()
* Mat4::from_rotation_translation(
Quat::from_rotation_z(-turn_input * tank.turn_speed * time.delta_seconds),
Vec3::unit_y() * drive * tank.speed * time.delta_seconds,
);
That was changed in Bevy 0.3 with "Move transform data out of Mat4" (PR #596)
This changed, so instead of Transform having a value: Mat4 field, then instead it would have translation: Vec3, rotation: Quat, and scale: Vec3.
If you want a literal translation of your code, then that would be:
transform = Transform::from_matrix(
transform.compute_matrix()
* Mat4::from_rotation_translation(
Quat::from_rotation_z(-turn_input * tank.turn_speed * time.delta_seconds),
Vec3::unit_y() * drive * tank.speed * time.delta_seconds,
),
);
However, it might be more straightforward to use transform.rotate() and/or assign directly to transform.translation and transform.rotation.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With