diff --git a/engine/physics/src/physics.rs b/engine/physics/src/physics.rs index 3b495b99..35d75a3a 100644 --- a/engine/physics/src/physics.rs +++ b/engine/physics/src/physics.rs @@ -57,6 +57,9 @@ impl InputState{ fn replace_mouse(&mut self,mouse:MouseState,next_mouse:MouseState){ (self.next_mouse,self.mouse)=(next_mouse,mouse); } + fn get_control(&mut self,control:Controls)->bool{ + self.controls.contains(control) + } fn set_control(&mut self,control:Controls,state:bool){ self.controls.set(control,state) } @@ -498,13 +501,19 @@ enum MoveState{ Ladder(ContactMoveState), #[expect(dead_code)] Water, - Fly, + Fly{no_clip:bool}, } impl MoveState{ + fn is_no_clip(&self)->bool{ + if let MoveState::Fly{no_clip}=self{ + return *no_clip; + } + false + } //call this after state.move_state is changed fn acceleration(&self,touching:&TouchingState,models:&PhysicsModels,hitbox_mesh:&HitboxMesh,style:&StyleModifiers,camera:&PhysicsCamera,input_state:&InputState)->Planar64Vec3{ match self{ - MoveState::Fly=>vec3::zero(), + MoveState::Fly{..}=>vec3::zero(), MoveState::Air |MoveState::Water =>{ @@ -523,7 +532,7 @@ impl MoveState{ match self{ MoveState::Air=>(), MoveState::Water=>(), - MoveState::Fly=>{ + MoveState::Fly{..}=>{ //set velocity according to current control state let v=style.get_propulsion_control_dir(camera,input_state.controls)*80; //set_velocity clips velocity according to current touching state @@ -537,7 +546,7 @@ impl MoveState{ /// changes the move state fn update_walk_target(&mut self,body:&Body,touching:&TouchingState,models:&PhysicsModels,hitbox_mesh:&HitboxMesh,style:&StyleModifiers,camera:&PhysicsCamera,input_state:&InputState){ match self{ - MoveState::Fly + MoveState::Fly{..} |MoveState::Air |MoveState::Water=>(), MoveState::Walk(ContactMoveState{target,contact,jump_direction:_})=>{ @@ -565,7 +574,7 @@ impl MoveState{ =>Some(walk_state), MoveState::Air |MoveState::Water - |MoveState::Fly + |MoveState::Fly{..} =>None, } } @@ -589,7 +598,7 @@ impl MoveState{ } }), MoveState::Water=>None,//TODO - MoveState::Fly=>None, + MoveState::Fly{..}=>None, } } fn set_move_state(&mut self,move_state:MoveState,body:&mut Body,touching:&TouchingState,models:&PhysicsModels,hitbox_mesh:&HitboxMesh,style:&StyleModifiers,camera:&PhysicsCamera,input_state:&InputState){ @@ -1195,6 +1204,11 @@ fn next_instruction_internal(state:&PhysicsState,data:&PhysicsData,time_limit:Ti let trajectory=state.body.with_acceleration(state.acceleration(data)); //check for collision ends state.touching.predict_collision_end(&mut collector,&data.models,&data.hitbox_mesh,&trajectory,state.time); + + if state.move_state.is_no_clip(){ + return collector.take(); + } + //check for collision starts let mut aabb=aabb::Aabb::default(); trajectory.grow_aabb(&mut aabb,state.time,collector.time()); @@ -1806,7 +1820,7 @@ fn atomic_internal_instruction(state:&mut PhysicsState,data:&PhysicsData,ins:Tim match &mut state.move_state{ MoveState::Air |MoveState::Water - |MoveState::Fly + |MoveState::Fly{..} =>println!("ReachWalkTargetVelocity fired for non-walking MoveState"), MoveState::Walk(walk_state)|MoveState::Ladder(walk_state)=>{ //velocity is already handled by extrapolated_body @@ -1841,7 +1855,7 @@ fn atomic_input_instruction(state:&mut PhysicsState,data:&PhysicsData,ins:TimedI Instruction::Mouse(_) |Instruction::SetControl(_)=>{ match &state.move_state{ - MoveState::Fly + MoveState::Fly{..} |MoveState::Water |MoveState::Walk(_) |MoveState::Ladder(_)=>true, @@ -1890,6 +1904,9 @@ fn atomic_input_instruction(state:&mut PhysicsState,data:&PhysicsData,ins:TimedI }, Instruction::SetControl(SetControlInstruction::SetSprint(s))=>{ state.input_state.set_control(Controls::Sprint,s); + if let MoveState::Fly{no_clip}=&mut state.move_state{ + *no_clip=s; + } }, Instruction::Mode(ModeInstruction::Reset)=>{ //totally reset physics state @@ -1935,11 +1952,12 @@ fn atomic_input_instruction(state:&mut PhysicsState,data:&PhysicsData,ins:TimedI }, Instruction::Misc(MiscInstruction::PracticeFly)=>{ match &state.move_state{ - MoveState::Fly=>{ + MoveState::Fly{..}=>{ state.set_move_state(data,MoveState::Air); }, _=>{ - state.set_move_state(data,MoveState::Fly); + let no_clip=state.input_state.get_control(Controls::Sprint); + state.set_move_state(data,MoveState::Fly{no_clip}); }, } b_refresh_walk_target=false;