Fix horizontal jittering along walls in 3D
This commit is contained in:
@@ -259,12 +259,12 @@ impl KinematicCharacterController {
|
|||||||
) {
|
) {
|
||||||
// No stairs, try to move along slopes.
|
// No stairs, try to move along slopes.
|
||||||
if let Some(translation_on_slope) =
|
if let Some(translation_on_slope) =
|
||||||
self.handle_slopes(&toi, &translation_remaining, offset)
|
self.handle_slopes(&toi, &translation_remaining)
|
||||||
{
|
{
|
||||||
translation_remaining = translation_on_slope;
|
translation_remaining = translation_on_slope;
|
||||||
} else if allowed_dist.abs() < 1.0e5 {
|
} else if allowed_dist.abs() < 1.0e5 {
|
||||||
// No slopes or stairs ahead, but we didn't move yet; try to move along obstacle.
|
// No slopes or stairs ahead, but we didn't move yet; try to move along obstacle.
|
||||||
let allowed_translation = subtract_hit(translation_remaining, &toi, offset);
|
let allowed_translation = subtract_hit(translation_remaining, &toi);
|
||||||
result.translation += allowed_translation;
|
result.translation += allowed_translation;
|
||||||
translation_remaining -= allowed_translation;
|
translation_remaining -= allowed_translation;
|
||||||
}
|
}
|
||||||
@@ -485,13 +485,12 @@ impl KinematicCharacterController {
|
|||||||
&self,
|
&self,
|
||||||
hit: &TOI,
|
hit: &TOI,
|
||||||
translation_remaining: &Vector<Real>,
|
translation_remaining: &Vector<Real>,
|
||||||
offset: Real,
|
|
||||||
) -> Option<Vector<Real>> {
|
) -> Option<Vector<Real>> {
|
||||||
let [vertical_translation, horizontal_translation] =
|
let [vertical_translation, horizontal_translation] =
|
||||||
self.split_into_components(translation_remaining);
|
self.split_into_components(translation_remaining);
|
||||||
let [vertical_slope_translation, horizontal_slope_translation] =
|
let [vertical_slope_translation, horizontal_slope_translation] =
|
||||||
[vertical_translation, horizontal_translation]
|
[vertical_translation, horizontal_translation]
|
||||||
.map(|remaining| subtract_hit(remaining, hit, offset));
|
.map(|remaining| subtract_hit(remaining, hit));
|
||||||
let slope_translation = horizontal_slope_translation + vertical_slope_translation;
|
let slope_translation = horizontal_slope_translation + vertical_slope_translation;
|
||||||
|
|
||||||
// Check if there is a slope to climb.
|
// Check if there is a slope to climb.
|
||||||
@@ -618,7 +617,7 @@ impl KinematicCharacterController {
|
|||||||
) {
|
) {
|
||||||
let [vertical_slope_translation, horizontal_slope_translation] = self
|
let [vertical_slope_translation, horizontal_slope_translation] = self
|
||||||
.split_into_components(translation_remaining)
|
.split_into_components(translation_remaining)
|
||||||
.map(|remaining| subtract_hit(remaining, &hit, offset));
|
.map(|remaining| subtract_hit(remaining, &hit));
|
||||||
|
|
||||||
let slope_translation = horizontal_slope_translation + vertical_slope_translation;
|
let slope_translation = horizontal_slope_translation + vertical_slope_translation;
|
||||||
|
|
||||||
@@ -745,8 +744,9 @@ impl KinematicCharacterController {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn subtract_hit(translation: Vector<Real>, hit: &TOI, offset: Real) -> Vector<Real> {
|
fn subtract_hit(translation: Vector<Real>, hit: &TOI) -> Vector<Real> {
|
||||||
let surface_correction = translation.dot(&hit.normal1).abs();
|
let surface_correction = (-translation).dot(&hit.normal1).max(0.0);
|
||||||
let surface_correction = surface_correction + offset;
|
// This fixes some instances of moving through walls
|
||||||
|
let surface_correction = surface_correction * (1.0 + 1.0e-5);
|
||||||
translation + *hit.normal1 * surface_correction
|
translation + *hit.normal1 * surface_correction
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user