Alright, so I'm working on collision detection for a 3d game, this is what I got so far:
public void mapCol(Spatial map, Node model2){
             Mesh m = (Mesh) ((Node) map).getChild("obj_mesh0");
              int c = 0;
              m.updateWorldBound(true);
              boolean col = false;
              c = m.getMeshData().getPrimitiveCount(0);
             // System.out.println(c);
              Vector3[][] v3 = new Vector3[c][3];
              for(int s = 0; s < c; s++){
                 v3[s] = null;
                 v3[s] = m.getMeshData().getPrimitive(s, 0, v3[s]);
                 Vector3 min = new Vector3((float)Math.min((float) Math.min(v3[s][0].getXf(), v3[s][1].getXf()), v3[s][2].getXf()),
                       (float)Math.min((float)Math.min(v3[s][0].getYf(), v3[s][1].getYf()), v3[s][2].getYf()),
                       (float)Math.min((float)Math.min(v3[s][0].getZf(), v3[s][1].getZf()), v3[s][2].getZf()));
                 Vector3 max = new Vector3((float) Math.max((float)Math.max(v3[s][0].getXf(), v3[s][1].getXf()), v3[s][2].getXf()),
                       (float)Math.max((float)Math.max(v3[s][0].getYf(), v3[s][1].getYf()), v3[s][2].getYf()),
                       (float)Math.max((float)Math.max(v3[s][0].getZf(), v3[s][1].getZf()), v3[s][2].getZf()));
                 Vector3 v2 = new Vector3();
                v2 = max.add(min, v2);
                v2.divideLocal(2);            
                 if(max.getXf() > model2.getTranslation().getXf() -  sp1.getRadius()&&
                    min.getXf() < model2.getTranslation().getXf() +  sp1.getRadius()  &&
                    max.getZf() > model2.ge开发者_运维技巧tTranslation().getZf()  -  sp1.getRadius()  &&
                    min.getZf() < model2.getTranslation().getZf()  + sp1.getRadius() &&
                    max.getYf() > model2.getTranslation().getYf() + sp1.getRadius()&&
                    !col){
                    float cosine = (float) v2.dot(v2);
                      float angle = (float) Math.toDegrees(Math.acos( cosine ));
                    float pangle = (float) Math.toDegrees(Math.atan2((min.getX() + ((max.getX() - min.getX())/2)) - model2.getTranslation().getX(), (min.getZ() + ((max.getZ() - min.getZ())/2) - model2.getTranslation().getZ())));
                    if(min.getY() < max.getY()){   
                       System.out.println("pangle:" + pangle + " angle:" + angle);
                       model2.setTranslation(
                             (min.getX() + ((max.getX() - min.getX())/2)) - (Math.sin(Math.toRadians(pangle)) * (sp1.getRadius())),
                                   model2.getTranslation().getYf(),
                                   (min.getZ() + ((max.getZ() - min.getZ())/2)) -  (-Math.cos(Math.toRadians(pangle)) * (sp1.getRadius()))
                             );
                       col = true;
}
                    }
                 }     
          }
Now the part to really look at is right here:
model2.setTranslation(
                             (min.getX() + ((max.getX() - min.getX())/2)) - (Math.sin(Math.toRadians(pangle)) * (sp1.getRadius())),
                                   model2.getTranslation().getYf(),
                                   (min.getZ() + ((max.getZ() - min.getZ())/2)) -  (-Math.cos(Math.toRadians(pangle)) * (sp1.getRadius()))
                             );
Any idea why it wouldn't set model2 modle2's radius away from the wall? (making it stop at the way and able to go no further)
float cosine = v2.dot(v2)
is intentional ?
Because it just gives you length of v2, squared.
Probably that should be
float cosine = velocity.dot(normalVector)/(velocity.length()*normalVector.length())
, if you wanted cosine of angle between them, but I don't fully understand your code, so I don't know.
 
         
                                         
                                         
                                         
                                        ![Interactive visualization of a graph in python [closed]](https://www.devze.com/res/2023/04-10/09/92d32fe8c0d22fb96bd6f6e8b7d1f457.gif) 
                                         
                                         
                                         
                                         加载中,请稍侯......
 加载中,请稍侯......
      
精彩评论