fix walk calculations

This commit is contained in:
Quaternions 2024-09-27 13:32:33 -07:00
parent def5497ec1
commit 4e111df791

View File

@ -321,16 +321,17 @@ impl WalkSettings{
if control_dir==crate::integer::vec3::ZERO{
return control_dir;
}
let n=normal.length_squared();
let m=control_dir.length_squared();
let nm=(n*m).fix_2();
let nn=normal.length_squared();
let mm=control_dir.length_squared();
let nnmm=nn*mm;
let d=normal.dot(control_dir);
if d<nm{
let dd=d*d;
if dd<nnmm{
let cr=normal.cross(control_dir);
if cr==crate::integer::vec3::ZERO_2{
crate::integer::vec3::ZERO
}else{
(cr.cross(normal)*self.accelerate.topspeed/(n*(nm*nm-d*d).sqrt())).divide().fix_1()
(cr.cross(normal)*self.accelerate.topspeed/((nn*(nnmm-dd)).sqrt())).divide().fix_1()
}
}else{
crate::integer::vec3::ZERO
@ -361,27 +362,29 @@ impl LadderSettings{
if control_dir==crate::integer::vec3::ZERO{
return control_dir;
}
let n=normal.length_squared();
let m=control_dir.length_squared();
let nm=(n*m).fix_2();
let mut d=normal.dot(control_dir);
if d<((-self.dot)*nm).fix_2(){
control_dir=Planar64Vec3::new([Planar64::ZERO,m.fix_1(),Planar64::ZERO]);
d=normal.y.fix_2();
}else if (self.dot*nm).fix_2()<d{
control_dir=Planar64Vec3::new([Planar64::ZERO,-m.fix_1(),Planar64::ZERO]);
d=-normal.y.fix_2();
let nn=normal.length_squared();
let mm=control_dir.length_squared();
let nnmm=nn*mm;
let d=normal.dot(control_dir);
let mut dd=d*d;
if (self.dot*self.dot*nnmm).fix_4()<dd{
if d.is_negative(){
control_dir=Planar64Vec3::new([Planar64::ZERO,mm.sqrt().fix_1(),Planar64::ZERO]);
}else{
control_dir=Planar64Vec3::new([Planar64::ZERO,-mm.sqrt().fix_1(),Planar64::ZERO]);
}
dd=(normal.y*normal.y).fix_4();
}
//n=d if you are standing on top of a ladder and press E.
//two fixes:
//- ladder movement is not allowed on walkable surfaces
//- fix the underlying issue
if d.abs()<nm.abs(){
if dd<nnmm{
let cr=normal.cross(control_dir);
if cr==crate::integer::vec3::ZERO_2{
crate::integer::vec3::ZERO
}else{
(cr.cross(normal)*self.accelerate.topspeed/(n*(nm*nm-d*d).sqrt())).divide().fix_1()
(cr.cross(normal)*self.accelerate.topspeed/((nn*(nnmm-dd)).sqrt())).divide().fix_1()
}
}else{
crate::integer::vec3::ZERO