34 lines
985 B
Rust
34 lines
985 B
Rust
use bevy::prelude::*;
|
|
|
|
#[derive(Component)]
|
|
#[require(Transform)]
|
|
pub struct AnimatedTransform {
|
|
pub translation: Vec3,
|
|
pub rotation: Quat,
|
|
pub scale: Vec3,
|
|
}
|
|
|
|
impl AnimatedTransform {
|
|
pub fn from_xyz(x: f32, y: f32, z: f32) -> Self {
|
|
AnimatedTransform {
|
|
translation: Vec3 { x, y, z },
|
|
rotation: Quat::IDENTITY,
|
|
scale: Vec3::ONE,
|
|
}
|
|
}
|
|
pub fn identity() -> Self {
|
|
AnimatedTransform {
|
|
translation: Vec3::ZERO,
|
|
rotation: Quat::IDENTITY,
|
|
scale: Vec3::ONE,
|
|
}
|
|
}
|
|
}
|
|
|
|
pub fn transform_animation(query: Query<(&mut Transform, &AnimatedTransform)>) {
|
|
for (mut transform, anim_transform) in query {
|
|
transform.translation = transform.translation.lerp(anim_transform.translation, 0.25);
|
|
transform.rotation = transform.rotation.lerp(anim_transform.rotation, 0.25);
|
|
transform.scale = transform.scale.lerp(anim_transform.scale, 0.25);
|
|
}
|
|
}
|