RayCasting yields inconsistent results

Hello,
I am trying to detect walls next to the player. In order to do so, I cast a ray from the player to the left and right of the camera and check if there is any collision every frame (the player is first person and does not have a model). The code for that:

public static WallInformation getClosestWall(Vector3f playerTranslation, Vector3f left) {
        Vector3f camPos = playerTranslation.add(0, 1.8f, 0);
        CollisionResults results = castRay(camPos, left);
        WallInformation wallInfo1 = new WallInformation(results, true);
        
        CollisionResults results2 = castRay(camPos, left.negate());
        WallInformation wallInfo2 = new WallInformation(results2, false);
        
        if(results.size() == 0 && results2.size() == 0) return null;
        if(results.size() > 0 && results2.size() == 0) return wallInfo1;
        if(results.size() == 0 && results2.size() > 0) return wallInfo2;
        return wallInfo1.getDistance() < wallInfo2.getDistance() ? wallInfo1 : wallInfo2;
    }
    
    
    private static CollisionResults castRay(Vector3f origin, Vector3f dir) {
        CollisionResults results = new CollisionResults();
        Ray ray = new Ray(origin, dir);
        Globals.worldNode.collideWith(ray, results);
        return results;
    }

Using the results from the CollisionResults, I move the player along the wall (using the cross product of the normal and the camera direction. This is not the problem however; it still persists if I simply move the player along the X-Axis).
While moving, I check if the wall is still there with the same method. Most of the time, it detects the wall correctly, but sometimes it does not detect any wall at all (results.size() and results2.size() are 0), even though the player just moved along the wall and there clearly is a wall to the left of him. Next frame the wall gets detected again and a frame later it is not detected.
The problem does also occur if I do not rotate the camera at all.

The code for moving the player is fairly simple:

public class WallrunPhysicsControl extends AbstractControl {
    
    private Vector3f wallrunDirection;
    private float speed = 1;
    
    @Override
    protected void controlUpdate(float tpf) {
        if(wallrunDirection == null) return;
        spatial.move(wallrunDirection.mult(tpf).mult(1*speed)); //.02
    }
    
    @Override
    protected void controlRender(RenderManager rm, ViewPort vp) {
    }
    
    public Vector3f getWallrunDirection() {
        return wallrunDirection;
    }

    public void setWallrunDirection(Vector3f wallrunDirection) {
        this.wallrunDirection = wallrunDirection;
    }
}

I really run out of ideas why this could happen…

Is the wall a quad?

Are you running JME 3.0 or 3.1?

No the wall is a scaled cube and I’m running 3.1. However, it seems that after remodelling the level in blender and reimporting it, it is working correctly now strangely :smiley:. If I have the issue again, I will post here.