Libgdx FirstPersonCamera smooth collision?

I have made collision for my game however it is horrible ??? every time i glide against a wall i get stuck and I have no idea how to imporve this other then not to use FirstPersonController (From Libgdx)

Code

public static Vector3 collision(MapModel map, Vector3 oldPos,Vector3 newPos, float width, float length) {
		int w = map.getPixMap().getWidth();
		int h = map.getPixMap().getHeight();
		
		
		
		float blockWidth = CreateMap.BLOCK_WIDTH;
		float blockLength = CreateMap.BLOCK_LENGTH;

		for (int x = 0; x < w; x++) {
			for (int z = 0; z < h; z++) {
				
				float blockPosX = x*blockWidth;
				float blockPosZ = z*blockLength;
				
				if(CreateMap.outBounds(map.getPixMap(), x, z)){
					if(newPos.x+width > blockPosX && newPos.x - width < blockPosX + blockWidth
							&& newPos.z+length > blockPosZ && newPos.z - length < blockPosZ + blockLength){
						return oldPos;
					}
				}
			}
		}
		return newPos;
	}

I think I offered this same advice previously on the forums (maybe in response to one of your posts), but I’ll mention it again here.

From what you posted, it seems that for the purposes of collision detection and response this is a 2-d environment represented by a regular grid, where (for the purposes of collision) grid cells are either empty or fully occupied.

One response you may get is to use an existing physics library, such as Box2D. That would be a fairly heavyweight solution for simply moving around in a grid-based environment, although if there are going to be other moving entities, a physics library would probably make things easier.

If you want to do it yourself though, fortunately this is one of the easier collision-related problems to solve. I would recommend though that if your player position refers to a corner of the player, you change it so that the position refers to the center of the player, as this will make things a lot easier. (I’m not entirely sure how you’re doing it currently, but I think sometimes when people get used to working with certain sprite-based frameworks they tend to anchor sprites in the corner rather than the center, even though this can be somewhat inconvenient as far as the simulation goes.)

I think the simplest thing you could possibly do is as follows. Represent your player as a circle. If the circle intersects an obstacle (the obstacles being squares representing occupied cells), compute the minimum translation vector that will resolve the collision, and move the player accordingly. As long as the player circle is smaller than a cell and as long as displacements aren’t large enough that tunneling might be an issue, this should give you good results, including natural sliding behavior.

If you want to pursue that I can help you with the math (which is simpler than you might expect). Or, you could always go with e.g. Box2D if that seems easier.

I know how to do collision but I am not completely sure on how to implement it using the FirstPersonController which Libgdx uses. I have made collision but it is very buggy and you keep getting stuck when gliding against a wall

I don’t know much about the LibGDX FirstPersonController class, but a quick look online suggests that it doesn’t deal with collision detection at all. Is that correct? If so, that means the problem of collision detection here is more or less orthogonal to whether you use the FirstPersonController class (in other words, whether or not you use the FirstPersonController class really doesn’t matter as far as collision detection goes).

If you already know how to do the collision detection correctly but feel the FirstPersonController class is interfering with your ability to implement it, perhaps you could specify exactly what problems you’re running into with respect to integrating the FirstPersonController class with your collision code.