From 4adce7acd3b731b6279bb8d5bb9cb5356c190080 Mon Sep 17 00:00:00 2001 From: Quaternions Date: Fri, 6 Oct 2023 15:45:22 -0700 Subject: [PATCH] fix cancollide false triggers + losing speed from hitting teleports why can't I make this into a function --- src/load_roblox.rs | 14 ++++---- src/physics.rs | 87 ++++++++++++++++++++++++++++++---------------- 2 files changed, 66 insertions(+), 35 deletions(-) diff --git a/src/load_roblox.rs b/src/load_roblox.rs index 3df6e01..dbec8ed 100644 --- a/src/load_roblox.rs +++ b/src/load_roblox.rs @@ -34,11 +34,12 @@ fn get_attributes(name:&str,can_collide:bool,velocity:glam::Vec3,force_intersect let mut general=crate::model::GameMechanicAttributes::default(); let mut intersecting=crate::model::IntersectingAttributes::default(); let mut contacting=crate::model::ContactingAttributes::default(); + let mut force_can_collide=can_collide; match name{ //"Water"=>intersecting.water=Some(crate::model::IntersectingWater{density:1.0,drag:1.0}), - "Accelerator"=>intersecting.accelerator=Some(crate::model::IntersectingAccelerator{acceleration:velocity}), - "MapFinish"=>general.zone=Some(crate::model::GameMechanicZone{mode_id:0,behaviour:crate::model::ZoneBehaviour::Finish}), - "MapAnticheat"=>general.zone=Some(crate::model::GameMechanicZone{mode_id:0,behaviour:crate::model::ZoneBehaviour::Anitcheat}), + "Accelerator"=>{force_can_collide=false;intersecting.accelerator=Some(crate::model::IntersectingAccelerator{acceleration:velocity})}, + "MapFinish"=>{force_can_collide=false;general.zone=Some(crate::model::GameMechanicZone{mode_id:0,behaviour:crate::model::ZoneBehaviour::Finish})}, + "MapAnticheat"=>{force_can_collide=false;general.zone=Some(crate::model::GameMechanicZone{mode_id:0,behaviour:crate::model::ZoneBehaviour::Anitcheat})}, "Platform"=>general.stage_element=Some(crate::model::GameMechanicStageElement{ mode_id:0, stage_id:0, @@ -57,14 +58,15 @@ fn get_attributes(name:&str,can_collide:bool,velocity:glam::Vec3,force_intersect }, behaviour:match &captures[2]{ "Spawn"|"SpawnAt"=>crate::model::StageElementBehaviour::SpawnAt, - "Trigger"=>crate::model::StageElementBehaviour::Trigger, - "Teleport"=>crate::model::StageElementBehaviour::Teleport, + "Trigger"=>{force_can_collide=false;crate::model::StageElementBehaviour::Trigger}, + "Teleport"=>{force_can_collide=false;crate::model::StageElementBehaviour::Teleport}, "Platform"=>crate::model::StageElementBehaviour::Platform, _=>panic!("regex1[2] messed up bad"), } }) }else if let Some(captures)=lazy_regex::regex!(r"^Bonus(Finish|Anticheat)(\d+)$") .captures(other){ + force_can_collide=false; match &captures[1]{ "Finish"=>general.zone=Some(crate::model::GameMechanicZone{mode_id:captures[2].parse::().unwrap(),behaviour:crate::model::ZoneBehaviour::Finish}), "Anticheat"=>general.zone=Some(crate::model::GameMechanicZone{mode_id:captures[2].parse::().unwrap(),behaviour:crate::model::ZoneBehaviour::Anitcheat}), @@ -77,7 +79,7 @@ fn get_attributes(name:&str,can_collide:bool,velocity:glam::Vec3,force_intersect if velocity!=glam::Vec3::ZERO{ general.booster=Some(crate::model::GameMechanicBooster{velocity}); } - match can_collide{ + match force_can_collide{ true=>{ match name{ //"Bounce"=>(), diff --git a/src/physics.rs b/src/physics.rs index 7081072..d3c0b72 100644 --- a/src/physics.rs +++ b/src/physics.rs @@ -1094,35 +1094,35 @@ impl crate::instruction::InstructionConsumer for PhysicsStat } //check ground self.contacts.insert(c.model,c); - match &general.stage_element{ - Some(stage_element)=>{ - if stage_element.force||self.game.stage_id(), - crate::model::StageElementBehaviour::Trigger - |crate::model::StageElementBehaviour::Teleport=>{ - //TODO make good - if let Some(mode)=self.get_mode(stage_element.mode_id){ - if let Some(&spawn)=mode.get_spawn_model_id(self.game.stage_id){ - if let Some(model)=self.models.get(spawn as usize){ - self.body.position=model.transform.transform_point3(glam::Vec3::Y)+glam::Vec3::Y*(self.style.hitbox_halfsize.y+0.1); - //manual clear //for c in self.contacts{process_instruction(CollisionEnd(c))} - self.contacts.clear(); - self.intersects.clear(); - self.body.acceleration=self.style.gravity; - self.walk.state=WalkEnum::Reached; - self.grounded=false; - }else{println!("bad1");} - }else{println!("bad2");} - }else{println!("bad3");} - }, - crate::model::StageElementBehaviour::Platform=>(), - } - }, - None=>(), - } + match &general.stage_element{ + Some(stage_element)=>{ + if stage_element.force||self.game.stage_id(), + crate::model::StageElementBehaviour::Trigger + |crate::model::StageElementBehaviour::Teleport=>{ + //TODO make good + if let Some(mode)=self.get_mode(stage_element.mode_id){ + if let Some(&spawn)=mode.get_spawn_model_id(self.game.stage_id){ + if let Some(model)=self.models.get(spawn as usize){ + self.body.position=model.transform.transform_point3(glam::Vec3::Y)+glam::Vec3::Y*(self.style.hitbox_halfsize.y+0.1); + //manual clear //for c in self.contacts{process_instruction(CollisionEnd(c))} + self.contacts.clear(); + self.intersects.clear(); + self.body.acceleration=self.style.gravity; + self.walk.state=WalkEnum::Reached; + self.grounded=false; + }else{println!("bad1");} + }else{println!("bad2");} + }else{println!("bad3");} + }, + crate::model::StageElementBehaviour::Platform=>(), + } + }, + None=>(), + } //flatten v let mut v=self.body.velocity; self.contact_constrain_velocity(&mut v); @@ -1142,6 +1142,35 @@ impl crate::instruction::InstructionConsumer for PhysicsStat PhysicsCollisionAttributes::Intersect{intersecting,general}=>{ //I think that setting the velocity to 0 was preventing surface contacts from entering an infinite loop self.intersects.insert(c.model,c); + match &general.stage_element{ + Some(stage_element)=>{ + if stage_element.force||self.game.stage_id(), + crate::model::StageElementBehaviour::Trigger + |crate::model::StageElementBehaviour::Teleport=>{ + //TODO make good + if let Some(mode)=self.get_mode(stage_element.mode_id){ + if let Some(&spawn)=mode.get_spawn_model_id(self.game.stage_id){ + if let Some(model)=self.models.get(spawn as usize){ + self.body.position=model.transform.transform_point3(glam::Vec3::Y)+glam::Vec3::Y*(self.style.hitbox_halfsize.y+0.1); + //manual clear //for c in self.contacts{process_instruction(CollisionEnd(c))} + self.contacts.clear(); + self.intersects.clear(); + self.body.acceleration=self.style.gravity; + self.walk.state=WalkEnum::Reached; + self.grounded=false; + }else{println!("bad1");} + }else{println!("bad2");} + }else{println!("bad3");} + }, + crate::model::StageElementBehaviour::Platform=>(), + } + }, + None=>(), + } }, } },