Some animations

This commit is contained in:
Rendo 2026-01-31 13:03:43 +05:00
commit 809d472c56
6 changed files with 71 additions and 31 deletions

View file

@ -4,17 +4,23 @@ use bevy::prelude::*;
#[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,
}
}
}
@ -22,5 +28,7 @@ impl AnimatedTransform {
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);
}
}