question?why checkForCollision worked only single side?

Started by Uncle Ray, September 01, 2014, 06:46:31 AM

Previous topic - Next topic

Uncle Ray

SOLVED THX EGO

1.
             │
         →→ │→→→→→→→→Passed
            │
The checkforcollision is not worked,pass through the plane   



2.                   

                 │
stoped       │←←←←
                  │
The checkforcollision worked,everyththing is work.



what is wrong,anyone can tell me how to solved it,thanks.             

EgonOlsen

The collision detection methods don't work on back faces. If you need this behaviour, you have to use separate objects (one normal, one inverted) at least during the collision detection stage (you might want to set the inverted object to invisible in the render stage).

Uncle Ray

but when object set invisible,all collision method will never work.
because all the collision_detect  without calmindistance(the only which can detect invisible object)
can not detect invisible object.

EgonOlsen

It doesn't matter if it's visible during rendering or not. It only matters what's visible when doing the collision detection. So you can add "collision objects" to the world that won't be rendered but used for collision detection only by altering their visibility between the two operations.

Uncle Ray

sorry,i am not clear got it.how to add "collision objects" to the world that won't be rendered ?



EgonOlsen

No, there are just regular objects. In your case, it would be a copy of your plane that is inverted. For example by calling invert(). It sits in the same location as the normal plane. In your case, you might not even have to deal with visibility because it might be feasible to let the plane visible all the time. But that depends on your scene. What are you using that plane for and has culling been disabled on it?

Uncle Ray

In my scene,i creat a car racing game,this plane is used for fense,i want it to be invsible,and keep the collition-detect,let the car runing in the track rightly.
how to make a invisble object ues the collide_detect(i know the calmindistance is ok,but others....)

EgonOlsen

If it's a fence, just build it in a way that it is two sided and you don't have to deal with visibility at all. You can't detect collisions on invisible objects...i guess, i'm still not clear enough on what i mean. It's basically this: You render one set of objects and you detect collisions on another one. There's no magic method that deals with this, you have to do this in your own code. I usually do it this way:


  • Create the renderable object (based on your own class like MyObject3D...more on that later)
  • Create the collision object
  • Make the collision mesh a child object of the renderable object
  • At a method to MyObject3D that toggles the states, like setCollisionMode(<boolean>);
  • If you set it to true, collision mesh will be visible. If set to false, renderable mesh will be visible.
  • Call setCollisionMode(false) on the object and do the rendering
  • Call setCollisionMode(true) on the object and do the collision detections

However, i don't think that this will be needed in your case. Just make a two sided model out of your fence (i.e. visible from both sides) and you are good to go.

Uncle Ray

I know your means,two objects set in the same place but  opposite backface(which is depended on opengl rendering clockwise or counterclockwise)

Here is my question
1.collide two sides?
your suggestion is right,the problem is solved.Thx,ego.

2.invisible object collide?
you said in jpct collide with invisible object was impossible.

Here is my idea:
could i bounding a texture which is transparent with the object.
Although the object setvisible(true),but it's texture is transparent,in fact we can't see the object.   

Is this the best method for the invisible object collide detect?
or,if there is better method,could your tell me how,
i dont want the detailed code,just the thought.

At last,thank ego again.for your huge help with me.

Uncle Ray

I found the second solution,if i want the "A" invisible and collideable,here is the code:

{
Object3D A;
A.setTransparency(0);
Config.glTransparencyOffset=0;
}

it's perfect,invisible,and all the collide method are worked.
last question,is there a better solution for invisible and colideable?

EgonOlsen

You could do that, but it causes additional overhead when rendering the scene. It might not be noticable though.

Uncle Ray

Thx,is there a better solution for invisible collide?


EgonOlsen

Yes...just what i said multiple times before: Alter the visibility between rendering and collision detection. In your case, set the transparent plane to invisible during rendering and you'll save the additional render cycles for processing it.