@@ -215,41 +215,43 @@ export default class Controls {
215215 }
216216
217217 updateHeights ( ) {
218- function between ( n , min , max ) {
219- return n >= min && n < max ;
220- }
218+ function between ( n , min , max ) {
219+ return n >= min && n < max ;
220+ }
221221
222- let inTile = ( pos , thisPos ) => {
223- return between ( pos . x , thisPos . x - this . tileSize . x , thisPos . x ) &&
224- between ( pos . z , thisPos . z - this . tileSize . z , thisPos . z ) ;
225- } ;
222+ let inTile = ( pos , thisPos ) => {
223+ return between ( pos . x , thisPos . x - this . tileSize . x , thisPos . x ) &&
224+ between ( pos . z , thisPos . z - this . tileSize . z , thisPos . z ) ;
225+ } ;
226226
227- let tileChildren = ( targetPos ) => {
228- return this . heightScene . children . filter ( child => inTile ( child . position , targetPos ) )
229- } ;
227+ let tileChildren = ( targetPos ) => {
228+ return this . heightScene . children . filter ( child => inTile ( child . position , targetPos ) )
229+ } ;
230230
231+ // check hight at target
232+ try {
231233 let rayStart = new Vector3 ( this . targetPosition . x , 300 , this . targetPosition . z ) ;
232234 this . raycaster . set ( rayStart , this . rayDirection ) ;
233235 this . raycaster . near = 1 ;
234236 this . raycaster . far = 300 ;
235237 let intersects = this . raycaster . intersectObjects ( tileChildren ( this . targetPosition ) ) ;
236238
237- if ( intersects . length > 0 ) {
239+ if ( intersects . length > 0 ) {
238240 this . minHeight = intersects [ 0 ] . point . y ;
239- //this.targetPosition.y = this.minHeight;
240- } else {
241- //this.targetPosition.y = 0;
242241 }
242+ } catch ( ignore ) { }
243243
244- rayStart . set ( this . camera . position . x , 300 , this . camera . position . z ) ;
244+ // check height at camera
245+ try {
246+ let rayStart = new Vector3 ( this . camera . position . x , 300 , this . camera . position . z ) ;
245247 this . raycaster . set ( rayStart , this . rayDirection ) ;
246- intersects . length = 0 ;
247- intersects = this . raycaster . intersectObjects ( tileChildren ( this . camera . position ) ) ;
248- if ( intersects . length > 0 ) {
249- if ( intersects [ 0 ] . point . y > this . minHeight ) {
248+ let intersects = this . raycaster . intersectObjects ( tileChildren ( this . camera . position ) ) ;
249+ if ( intersects . length > 0 ) {
250+ if ( intersects [ 0 ] . point . y > this . minHeight ) {
250251 this . minHeight = intersects [ 0 ] . point . y ;
251252 }
252253 }
254+ } catch ( ignore ) { }
253255 }
254256
255257 updateMouseMoves = ( ) => {
0 commit comments