use origin instead of pivot

and use trimesh instead of convex
This commit is contained in:
2025-03-08 19:48:41 +01:00
parent 59b23aadc9
commit 99a9d2b374
5 changed files with 109 additions and 162 deletions

View File

@@ -1,9 +1,9 @@
use std::collections::HashMap;
use avian3d::math::PI;
use bevy::{prelude::*, state::commands};
use bevy::prelude::*;
use crate::tb_entities::{NamedEntity, Pivot};
use crate::tb_entities::NamedEntity;
#[derive(Resource)]
enum GatesState {
@@ -19,8 +19,7 @@ pub fn plugin(app: &mut App) {
fn update(
keyboard: Res<ButtonInput<KeyCode>>,
mut state: ResMut<GatesState>,
mut names_entities: Query<(&NamedEntity, &mut Transform), Without<Pivot>>,
pivot_entities: Query<(&Pivot, &Transform)>,
mut names_entities: Query<(&NamedEntity, &mut Transform)>,
) {
if keyboard.just_pressed(KeyCode::Digit1) {
if matches!(*state, GatesState::Init) {
@@ -35,15 +34,7 @@ fn update(
for (named_entity, mut transform) in names_entities.iter_mut() {
if let Some(fence) = fences.get(named_entity.name.as_str()) {
let Some((_, t)) = pivot_entities
.iter()
.find(|(p, _)| &p.name == named_entity.name.as_str())
else {
warn!("Pivot not found for {}", named_entity.name);
continue;
};
transform.rotate_around(t.translation, *fence);
transform.rotate(*fence);
}
}
}

View File

@@ -32,20 +32,14 @@ impl SpawnPoint {
#[derive(SolidClass, Component, Reflect)]
#[reflect(Component)]
#[geometry(GeometryProvider::new().convex_collider().smooth_by_default_angle().render())]
#[geometry(GeometryProvider::new().trimesh_collider().smooth_by_default_angle().render())]
pub struct Worldspawn;
#[derive(SolidClass, Component, Reflect, Default)]
#[reflect(Component)]
#[geometry(GeometryProvider::new().convex_collider().smooth_by_default_angle().render())]
pub struct NamedEntity {
pub name: String,
}
#[derive(PointClass, Component, Reflect, Default)]
#[reflect(Component)]
#[require(Transform)]
pub struct Pivot {
#[geometry(GeometryProvider::new().trimesh_collider().smooth_by_default_angle().render())]
pub struct NamedEntity {
pub name: String,
}
@@ -67,17 +61,23 @@ impl EnemySpawn {
world
.commands()
.entity(entity)
.insert((
Visibility::default(),
RigidBody::Dynamic,
Collider::capsule(0.2, 1.),
LockedAxes::new().lock_rotation_z().lock_rotation_x(),
Name::from("Enemy"),
))
.with_child((
Transform::from_translation(Vec3::new(0., -0.6, 0.)).with_scale(Vec3::splat(1.5)),
SceneRoot(mesh),
));
.insert((Name::from("Enemy"), Visibility::default()))
.with_children(|parent| {
parent
.spawn((
Visibility::default(),
RigidBody::Dynamic,
Collider::capsule(0.4, 2.),
LockedAxes::new().lock_rotation_z().lock_rotation_x(),
Transform::from_translation(Vec3::new(0., 1.0, 0.)),
))
.with_child((
Visibility::default(),
Transform::from_translation(Vec3::new(0., -1.4, 0.))
.with_scale(Vec3::splat(1.5)),
SceneRoot(mesh),
));
});
}
}