xx 1 năm trước cách đây
mục cha
commit
8679bbf82d
1 tập tin đã thay đổi với 23 bổ sung12 xóa
  1. 23 12
      assets/script/game/game.ts

+ 23 - 12
assets/script/game/game.ts

@@ -236,7 +236,8 @@ export class game extends Component {
 
     carCollider(car_rect:Rect){
         let list = []
-        // console.log("this.gameBoxList",this.gameBoxList,this.gameWallList)
+        let origin_car_pos = this.car.position
+        let origin_car_pos_y = origin_car_pos.y+car_rect.height*0.5
         let isColliderBox = false
         for (let index = 0; index < this.gameBoxList.length; index++) {
             const box_node = this.gameBoxList[index];
@@ -250,18 +251,23 @@ export class game extends Component {
                 let dir = -1
                 if(car_rect.intersects(rect)){
                     isColliderBox = true
-                    let car_top_rect = new Rect(car_rect.xMin,car_rect.yMax-10,car_rect.width,20)
+                    // let car_top_rect = new Rect(car_rect.xMin,car_rect.yMax-10,car_rect.width,20)
                     let box_bottom_rect = new Rect(rect.xMin,rect.yMin,rect.width,20)
-                
-                    if(car_top_rect.intersects(box_bottom_rect)){
-                        dir = config.collider_dir.top
+                    if(origin_car_pos_y<box_bottom_rect.yMin){
+                        // if((car_top_rect.yMin-origin_car_pos_y)>20){
+
+                        // }
+                        // if(car_top_rect.intersects(box_bottom_rect)){
+                            dir = config.collider_dir.top
+                        // }
                     }
+            
 
                     list.push({"node":box_node,"rect":rect,"type":0,"collider_dir":dir,"moveOffset":0})
                 }
             }
         }
-
+        let car_top_rect = new Rect(car_rect.xMin,car_rect.yMax-5,car_rect.width,10)
         for (let index = 0; index < this.gameWallList.length; index++) {
             const box_node = this.gameWallList[index];
             let isCanCollider = box_node.getComponent(wall).getIsCanCollider()
@@ -274,18 +280,23 @@ export class game extends Component {
                 let dir = -1
                 let offset = 0
                 if(car_rect.intersects(rect)){
-                    let car_top_rect = new Rect(car_rect.xMin,car_rect.yMax-5,car_rect.width,10)
                     let box_bottom_rect = new Rect(rect.xMin,rect.yMin,rect.width,10)
-                    if(car_top_rect.intersects(box_bottom_rect)){
-                        dir = config.collider_dir.top
-                        // if(!isColliderBox){
+                    // if(car_top_rect.intersects(box_bottom_rect)){
+                    //     dir = config.collider_dir.top
+                    //         if(box_bottom_rect.xMax>(car_top_rect.xMin+car_top_rect.width*0.5)){ //右边
+                    //             offset = (car_top_rect.width*0.5)
+                    //         }else{
+                    //             offset = (car_top_rect.width*-0.5)
+                    //         }
+                  
+                    // }
+                    if(origin_car_pos_y<box_bottom_rect.yMin){
+                            dir = config.collider_dir.top
                             if(box_bottom_rect.xMax>(car_top_rect.xMin+car_top_rect.width*0.5)){ //右边
                                 offset = (car_top_rect.width*0.5)
                             }else{
                                 offset = (car_top_rect.width*-0.5)
                             }
-                        // }
-                  
                     }
                     list.push({"node":box_node,"rect":rect,"type":1,"collider_dir":dir,"moveOffset":offset})
                 }