From a4b22e4b3761ede9cfecd5d018b394d56e75b644 Mon Sep 17 00:00:00 2001 From: Stephen Gold Date: Tue, 18 Jun 2019 08:36:44 -0700 Subject: [PATCH] fix for issue #1126 (TestHoveringTank assertion failures) --- .../java/jme3test/bullet/PhysicsHoverControl.java | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/jme3-examples/src/main/java/jme3test/bullet/PhysicsHoverControl.java b/jme3-examples/src/main/java/jme3test/bullet/PhysicsHoverControl.java index f914f5da5..901b3433c 100644 --- a/jme3-examples/src/main/java/jme3test/bullet/PhysicsHoverControl.java +++ b/jme3-examples/src/main/java/jme3test/bullet/PhysicsHoverControl.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2009-2018 jMonkeyEngine + * Copyright (c) 2009-2019 jMonkeyEngine * All rights reserved. * * Redistribution and use in source and binary forms, with or without @@ -146,6 +146,7 @@ public class PhysicsHoverControl extends PhysicsVehicle implements PhysicsContro Vector3f dir = getForwardVector(tempVect2).multLocal(1, 0, 1).normalizeLocal(); getLinearVelocity(tempVect3); Vector3f linearVelocity = tempVect3.multLocal(1, 0, 1); + float groundSpeed = linearVelocity.length(); if (steeringValue != 0) { if (rotationVelocity < 1 && rotationVelocity > -1) { @@ -164,16 +165,18 @@ public class PhysicsHoverControl extends PhysicsVehicle implements PhysicsContro // if we are not going where we want to go. // this will prevent "drifting" and thus improve control // of the vehicle - float d = dir.dot(linearVelocity.normalize()); - Vector3f counter = dir.project(linearVelocity).normalizeLocal().negateLocal().multLocal(1 - d); - applyForce(counter.multLocal(mass * 10), Vector3f.ZERO); + if (groundSpeed > FastMath.ZERO_TOLERANCE) { + float d = dir.dot(linearVelocity.normalize()); + Vector3f counter = dir.project(linearVelocity).normalizeLocal().negateLocal().multLocal(1 - d); + applyForce(counter.multLocal(mass * 10), Vector3f.ZERO); + } if (linearVelocity.length() < 30) { applyForce(dir.multLocal(accelerationValue), Vector3f.ZERO); } } else { // counter the acceleration value - if (linearVelocity.length() > FastMath.ZERO_TOLERANCE) { + if (groundSpeed > FastMath.ZERO_TOLERANCE) { linearVelocity.normalizeLocal().negateLocal(); applyForce(linearVelocity.mult(mass * 10), Vector3f.ZERO); }