only walk if grounded

This commit is contained in:
Quaternions 2023-09-18 21:28:09 -07:00
parent 0632e322cf
commit fd38502e07

View File

@ -400,7 +400,7 @@ impl PhysicsState {
fn next_walk_instruction(&self) -> Option<TimedInstruction<PhysicsInstruction>> {
//check if you have a valid walk state and create an instruction
if self.walk.body_hash==self.body.hash(){
if self.grounded&&self.walk.body_hash==self.body.hash(){
Some(TimedInstruction{
time:self.walk.target_time,
instruction:PhysicsInstruction::ReachWalkTargetVelocity
@ -754,6 +754,7 @@ impl crate::instruction::InstructionConsumer<PhysicsInstruction> for PhysicsStat
}
PhysicsInstruction::SetWalkTargetVelocity(v) => {
//calculate acceleration yada yada
if self.grounded{
let target_diff=v-self.body.velocity;
if target_diff==glam::Vec3::ZERO{
self.body.acceleration=glam::Vec3::ZERO;
@ -765,6 +766,7 @@ impl crate::instruction::InstructionConsumer<PhysicsInstruction> for PhysicsStat
self.walk.target_time=self.body.time+((time_delta as f64)*1_000_000_000f64) as TIME;
self.walk.body_hash=self.body.hash();//hash check to see if walk target is valid
}
}
},
}
}