LibGDX Problems when using an Orthographic Camera and Bullet

Hi everyone. As you can see this is my first post on here. I’ve lurked for a while now and I’ve decided to join the community.

I’m still inexperienced with LibGDX and i’m working on developing my first 3D project. I’m having issues when using an Orthographic Camera, hit detection with the Camera Ray and Bullet collision detection. I’ve been struggling on this for a while and i can’t find a solution. When i have the Camera positioned at (5, 5, 10) the RayCallback works perfectly. I can click on the objects and a hit is registered inside the TouchDown code. However, when i pan around the map i get this camera clipping effect which cuts out the lower area of map which i am trying to view.

Here is a preview of the RayCallback detecting hits on the objects.

I have tried changing the Camera position to make it much further out (such as 50,50,50 or 100,100,100) and also changing the Camera.near/Camera.far values. This fixes the map clipping issue and the view of the map looks exactly the same, but it causes my hit detection on my RayCallback to stop detecting anything. I don’t understand why it works at 5,5,10 and not 100,100,100?

Here is a preview of a Camera which i have positioned at 50,50,50 no longer clipping the map but the hit detection has stopped working

Alternatively i have tried using a different RayCallback using this code;

    public int getObject (int screenX, int screenY) {
        Ray ray = cam.getPickRay(screenX, screenY);
        int result = -1;
        float distance = -1;
        for (int i = 0; i < instances.size; ++i) {
            final GameObject instance = instances.get(i);
            instance.transform.getTranslation(position);
            position.add(instance.center);
            float dist2 = ray.origin.dst2(position);
            if (distance >= 0f && dist2 > distance) continue;
            if (Intersector.intersectRaySphere(ray, position, instance.radius, null)) {
                result = i;
                distance = dist2;
            }
        }
        return result;
    }

Like the RayCallback code, It works at 5,5,10 but instead of not working at 50,50,50 - it fills the entire world map. I receive a hit no matter where i click on the screen.

I don’t normally ask for help because i can find the answers to most of my questions through a quick google search. Apologies if this question has been asked before - i can’t find anything on it.

You can view my full code here.

Figured i would post a small update on this since it’s been over 24 hours.

So I’ve played around with the position of the map to fix the camera clipping issue by reversing it’s direction. However the RayCallback is still a problem. There seems to be a range on how far the hit detection stretches back. It recognises anything within a range of around [0,0] to [16,16] and then it stops dead. It also seems to be a little fuzzy around the edge of it’s range where it only detects hits sometimes. I’ve created a gif to show an example of what i’m talking about.

In this gif I’m hitting the same spots several times, sometimes it registers a hit and sometimes it doesn’t. I’m now wondering if the reason for these inconsistencies is because my Camera movement code is wrong? I’m not sure that’s the problem but i’m really lost on this one.

Do you guys have any opinions or advice? I really appreciate any help i can get.

  1. about your depth clipping problem:
    The animations in your first post clearly show that when you move “up” and “down” you are moving your 3D camera along its view plane that is at an angle to the blue “floor”. It is at an angle because you wanted to have this isometric projection. But even though you are using an orthographic projection, it is still just a projection, and your objects are still in 3D. So when you just move far enough down you’d end up hitting the floor with your camera. So, obviously you need to move the camera parallel to your blue floor, so that the depth bounds remain the same.

  2. about your ray picking problem:
    Yes, it seems that Bullet’s CollisionWorld.rayTest() does not test a “ray” against the world but instead a line segment, defined between two end points. So, make sure that the second endpoint is sufficiently far away.

Thank you for your help!

First of all what you said about the raytest. I didn’t know it was just a test between 2 points. What you said does make sense and with those 2 points obviously being the RayTo and RayFrom i was able to finally correct that issue. Nothing like struggling for a week on an issue and solving it by simply typing one extra 0 onto the end of a number.

Regarding the Camera. I’m still bad at working with cameras. I placed the map at z=0 and the Camera at z=10 and i only move the camera along the x and y axis. I figured this would avoid any unwanted collisions between the two and so it’s hard for me to understand why the clipping happens. As I’m still inexperienced in working with this stuff i find it difficult to visualise how my map and my camera actually look in a 3D space. I guess i need to move the z axis along with the x and y to maintain a sufficient distance from the map? I’m bad at coding camera movements but at least now i know what the issue is, i can work on correcting it.

No, you don’t. In your linked source code the method DragProcess() clearly shows that you are moving the camera along its own local “right” and “up” vectors, by computing them from the camera’s direction/forward and up vectors using a cross product. Note that those vectors are expressed with respect to the world coordinate system. The whole problem now is that the “up” and “direction” vectors are directed towards the floor and moving along “up” will lead to moving away from/towards the floor. You must compute a movement vector which is parallel to the floor.