Fixed landing collisions

master
Mark 2024-01-13 21:55:23 -08:00
parent 0995e2311b
commit 6406fd8786
Signed by: Mark
GPG Key ID: C6D63995FE72FD80
5 changed files with 28 additions and 9 deletions

View File

@ -1,7 +1,6 @@
## Specific Jobs ## Specific Jobs
- Fix angles (point, land) - Fix angles (point, land)
- Land from farther away - Land from farther away
- Land collider
- Take off - Take off
- UI: text arranger - UI: text arranger
- Start documenting - Start documenting

View File

@ -66,7 +66,7 @@ impl<'a> Game {
ShipHandle { index: 0 }, ShipHandle { index: 0 },
FactionHandle { index: 1 }, FactionHandle { index: 1 },
ShipPersonality::Point, ShipPersonality::Point,
Point2::new(100.0, 0.0), Point2::new(400.0, 0.0),
); );
let s = systemsim.get_ship_mut(&a).unwrap(); let s = systemsim.get_ship_mut(&a).unwrap();
@ -79,7 +79,7 @@ impl<'a> Game {
ShipHandle { index: 0 }, ShipHandle { index: 0 },
FactionHandle { index: 0 }, FactionHandle { index: 0 },
ShipPersonality::Dummy, ShipPersonality::Dummy,
Point2::new(0.0, 120.0), Point2::new(0.0, 4000.0),
); );
let s = systemsim.get_ship_mut(&a).unwrap(); let s = systemsim.get_ship_mut(&a).unwrap();

View File

@ -4,7 +4,7 @@ use nalgebra::{Point2, Vector2};
use rapier2d::{ use rapier2d::{
dynamics::{RigidBody, RigidBodyBuilder, RigidBodyHandle, RigidBodySet}, dynamics::{RigidBody, RigidBodyBuilder, RigidBodyHandle, RigidBodySet},
geometry::{ColliderHandle, ColliderSet}, geometry::{ColliderHandle, ColliderSet, Group, InteractionGroups},
}; };
use std::collections::HashMap; use std::collections::HashMap;
@ -62,7 +62,7 @@ impl PhysSim {
position: Point2<f32>, position: Point2<f32>,
) -> PhysSimShipHandle { ) -> PhysSimShipHandle {
let ship_content = ct.get_ship(handle); let ship_content = ct.get_ship(handle);
let cl = ship_content.collider.0.clone(); let mut cl = ship_content.collider.0.clone();
// TODO: additonal ship mass from outfits and cargo // TODO: additonal ship mass from outfits and cargo
let rb = RigidBodyBuilder::dynamic() let rb = RigidBodyBuilder::dynamic()
@ -71,6 +71,11 @@ impl PhysSim {
.translation(Vector2::new(position.x, position.y)) .translation(Vector2::new(position.x, position.y))
.can_sleep(false); .can_sleep(false);
cl.set_collision_groups(InteractionGroups::new(
Group::GROUP_1,
Group::GROUP_1 | Group::GROUP_2,
));
let ridid_body = self.rigid_body_set.insert(rb.build()); let ridid_body = self.rigid_body_set.insert(rb.build());
let collider = let collider =
self.collider_set self.collider_set

View File

@ -1,7 +1,11 @@
use galactica_content::{GunPoint, OutfitHandle, ProjectileCollider}; use galactica_content::{GunPoint, OutfitHandle, ProjectileCollider};
use nalgebra::{Rotation2, Vector2}; use nalgebra::{Rotation2, Vector2};
use rand::Rng; use rand::Rng;
use rapier2d::{dynamics::RigidBodyBuilder, geometry::ColliderBuilder, pipeline::ActiveEvents}; use rapier2d::{
dynamics::RigidBodyBuilder,
geometry::{ColliderBuilder, Group, InteractionGroups},
pipeline::ActiveEvents,
};
use crate::{ use crate::{
data::{ShipAutoPilot, ShipState}, data::{ShipAutoPilot, ShipState},
@ -176,13 +180,15 @@ impl PhysSim {
.linvel(vel) .linvel(vel)
.build(); .build();
let collider = match &outfit.projectile.collider { let mut collider = match &outfit.projectile.collider {
ProjectileCollider::Ball(b) => ColliderBuilder::ball(b.radius) ProjectileCollider::Ball(b) => ColliderBuilder::ball(b.radius)
.sensor(true) .sensor(true)
.active_events(ActiveEvents::COLLISION_EVENTS) .active_events(ActiveEvents::COLLISION_EVENTS)
.build(), .build(),
}; };
collider.set_collision_groups(InteractionGroups::new(Group::GROUP_2, Group::GROUP_1));
let rigid_body = self.rigid_body_set.insert(rigid_body); let rigid_body = self.rigid_body_set.insert(rigid_body);
let collider = self.collider_set.insert_with_parent( let collider = self.collider_set.insert_with_parent(
collider, collider,

View File

@ -1,6 +1,9 @@
use galactica_content::{Content, Relationship, SystemObjectHandle}; use galactica_content::{Content, Relationship, SystemObjectHandle};
use nalgebra::{Isometry2, Point2, Vector2}; use nalgebra::{Isometry2, Point2, Vector2};
use rapier2d::{dynamics::RigidBody, geometry::ColliderHandle}; use rapier2d::{
dynamics::RigidBody,
geometry::{ColliderHandle, Group, InteractionGroups},
};
use crate::{ use crate::{
data::ShipState, data::ShipState,
@ -66,6 +69,9 @@ impl PhysSim {
return false; return false;
} }
let collider = self.collider_set.get_mut(collider).unwrap();
println!("{:?}", collider.collision_groups());
collider.set_collision_groups(InteractionGroups::new(Group::GROUP_1, Group::empty()));
ship.data.start_land_on(target_handle); ship.data.start_land_on(target_handle);
return true; return true;
} }
@ -102,7 +108,10 @@ impl PhysSim {
self.collider_set self.collider_set
.get_mut(ship.collider) .get_mut(ship.collider)
.unwrap() .unwrap()
.set_enabled(true); .set_collision_groups(InteractionGroups::new(
Group::GROUP_1,
Group::GROUP_1 | Group::GROUP_2,
));
} }
pub(super) fn remove_ship( pub(super) fn remove_ship(