jPCT-AE - a 3d engine for Android => Support => Topic started by: haijin on May 01, 2011, 02:23:01 pm

Title: Understanding collisions in 3D
Post by: haijin on May 01, 2011, 02:23:01 pm
Ok, solved... the second (preferred) alternative works. It's just that I wasn't setting the collision mode to SELF (only OTHERS). Still not sure about the use of the axis vectors...
Hi, this is my second post, and it's about time to thank the developers on their effort to create an easy and comfortable 3D engine. After a project directly working with opengl (Trapped, for Android), this is a welcomed change.
That said, my 3d math knowledge is quite limited and conflicting with implementation of collisions. I am working on a top down view game with NPCs trying to catch the main character. Now I want to have the NPCs avoid each other (i.e. no overlapping) when stalking the player.
I first tried without checking the corresponding examples, sending to checkForCollisionSpherical() the transformation that I would send to translate() (thinking the collision would be based on the transformed position, but also trying to add the current transformed position). Seeing that wouldn't work I checked the wiki and I see the use of getX/Z/YAxis() which I don't quite understand, still tried to implement it, obviously with no success... here's the alternatives I have tried:
Code: [Select]
       if (false){
            SimpleVector center = getTransformedCenter();
            SimpleVector t = new SimpleVector(speedX + center.x, speedY + center.y, center.z);
            SimpleVector avoid = checkForCollisionSpherical(t, 5f);
            if (avoid.equals(t))
                translate(speedX, speedY, 0);
        if (false){
            SimpleVector avoid = checkForCollisionSpherical(new SimpleVector(speedX, speedY, 0), 5f);
        if (true){
            //SimpleVector move = new SimpleVector();//getTransformedCenter();
            SimpleVector t = getXAxis();
            t = getYAxis();
            move.z = 0;

            move = checkForCollisionSpherical(move, 5f);
any hints/links/explanations on how this works would be appreciated...
Title: Re: Understanding collisions in 3D
Post by: EgonOlsen on May 01, 2011, 09:35:01 pm
I'm not quite sure, where the problem in your understanding is here...all collision detection is done in world space. The position vector (if any) and the direction vectors are all in world space. How to get them highly depends on your application. getXAxis and getZAxis are used in the examples but that doesn't mean that this is needed nor useful in your case.

If you know how to translate your object without doing any collision detection, you already know which vector to use for translation in the collision detection. If it doesn't work, make sure that collision mode is properly set on all objects.
Title: Re: Understanding collisions in 3D
Post by: haijin on May 01, 2011, 09:48:07 pm
Yes, I first assumed the collision was done on world coordinates but, when my implementation didn't work and after looking around the forums, I messed up and went off the right path :) the issue was not setting the collision mode right... I'll try to post some real problem next time :P