forked from StrafesNET/strafe-client
only walk if grounded
This commit is contained in:
parent
0632e322cf
commit
fd38502e07
24
src/body.rs
24
src/body.rs
@ -400,7 +400,7 @@ impl PhysicsState {
|
|||||||
|
|
||||||
fn next_walk_instruction(&self) -> Option<TimedInstruction<PhysicsInstruction>> {
|
fn next_walk_instruction(&self) -> Option<TimedInstruction<PhysicsInstruction>> {
|
||||||
//check if you have a valid walk state and create an instruction
|
//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{
|
Some(TimedInstruction{
|
||||||
time:self.walk.target_time,
|
time:self.walk.target_time,
|
||||||
instruction:PhysicsInstruction::ReachWalkTargetVelocity
|
instruction:PhysicsInstruction::ReachWalkTargetVelocity
|
||||||
@ -754,16 +754,18 @@ impl crate::instruction::InstructionConsumer<PhysicsInstruction> for PhysicsStat
|
|||||||
}
|
}
|
||||||
PhysicsInstruction::SetWalkTargetVelocity(v) => {
|
PhysicsInstruction::SetWalkTargetVelocity(v) => {
|
||||||
//calculate acceleration yada yada
|
//calculate acceleration yada yada
|
||||||
let target_diff=v-self.body.velocity;
|
if self.grounded{
|
||||||
if target_diff==glam::Vec3::ZERO{
|
let target_diff=v-self.body.velocity;
|
||||||
self.body.acceleration=glam::Vec3::ZERO;
|
if target_diff==glam::Vec3::ZERO{
|
||||||
}else{
|
self.body.acceleration=glam::Vec3::ZERO;
|
||||||
let accel=self.walk_accel.min(self.gravity.length()*self.friction);
|
}else{
|
||||||
let time_delta=target_diff.length()/accel;
|
let accel=self.walk_accel.min(self.gravity.length()*self.friction);
|
||||||
self.body.acceleration=target_diff/time_delta;
|
let time_delta=target_diff.length()/accel;
|
||||||
self.walk.target_velocity=v;
|
self.body.acceleration=target_diff/time_delta;
|
||||||
self.walk.target_time=self.body.time+((time_delta as f64)*1_000_000_000f64) as TIME;
|
self.walk.target_velocity=v;
|
||||||
self.walk.body_hash=self.body.hash();//hash check to see if walk target is valid
|
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
|
||||||
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user