소스 검색

Fix for wrong calculation of velocity

The velocity, which is the global cameraDirection variable was
constantly changed. Gravity was added to it over and over again.
This doesn't solve this -
http://www.html5gamedevs.com/topic/17708-collision-issue-with-bounce/ ,
but solves a problem with calculating the correct velocity currently
used.
Raanan Weber 10 년 전
부모
커밋
f7b1f90efc
1개의 변경된 파일6개의 추가작업 그리고 2개의 파일을 삭제
  1. 6 2
      src/Cameras/babylon.freeCamera.ts

+ 6 - 2
src/Cameras/babylon.freeCamera.ts

@@ -189,12 +189,16 @@
             globalPosition.subtractFromFloatsToRef(0, this.ellipsoid.y, 0, this._oldPosition);
             this._collider.radius = this.ellipsoid;
 
+			//no need for clone, as long as gravity is not on.
+			var actualVelocity = velocity;
+			
             //add gravity to the velocity to prevent the dual-collision checking
             if (this.applyGravity) {
-                velocity.addInPlace(this.getScene().gravity);
+				//this prevents mending with cameraDirection, a global variable of the free camera class.
+                actualVelocity = velocity.add(this.getScene().gravity);
             }
 
-            this.getScene().collisionCoordinator.getNewPosition(this._oldPosition, velocity, this._collider, 3, null, this._onCollisionPositionChange, this.uniqueId);
+            this.getScene().collisionCoordinator.getNewPosition(this._oldPosition, actualVelocity, this._collider, 3, null, this._onCollisionPositionChange, this.uniqueId);
 
         }