www.jpct.net

jPCT - a 3d engine for Java => Support => Topic started by: fireside on February 20, 2008, 06:13:02 am

Title: Collision not working
Post by: fireside on February 20, 2008, 06:13:02 am
I tried doing a search for collision and came up with this function for the mouse:
Code: [Select]
private void doGravity()
{
      SimpleVector msPos=Mouse.getTransformedCenter();
      msPos.add(msHgt);
      if(world.checkCollision(msPos, dr, .6f)== Object3D.NO_OBJECT)
      {
    Mouse.translate(gravity); 
      }           
}
private void move()
{
SimpleVector a = Mouse.getZAxis();
a.scalarMul(-.15f);
a = Mouse.checkForCollisionEllipsoid(a, elipse, 2);
Mouse.translate(a);
}

The gravity part works, but the mouse walks through as in this picture:
(http://aycu38.webshots.com/image/42837/2002542622528098855_th.jpg) (http://allyoucanupload.webshots.com/v/2002542622528098855)

The elipse is (2,5,2)  The five is the mouse height and works for gravity.

The platform is set for collision with this code:
Code: [Select]
    platform.setCollisionMode(Object3D.COLLISION_CHECK_OTHERS);
    platform.setCollisionOptimization(Object3D.COLLISION_DETECTION_OPTIMIZED);

I tried setting collision for the mouse but it didn't help.  I had to use -.15 in the scalermult or else the mouse went backwards.
Title: Re: Collision not working
Post by: EgonOlsen on February 20, 2008, 08:11:54 am
Does the mouse starts in that location or is he in front of that block in the beginning?
Title: Re: Collision not working
Post by: fireside on February 20, 2008, 08:20:53 am
He's in front of the block and walks right through it.
Title: Re: Collision not working
Post by: EgonOlsen on February 20, 2008, 08:34:24 am
How much in front? Make sure that the ellipsoid doesn't intersect with the block at the beginning, because the ellipsoid collision detection is a collision avoidance algorithm. It can't resolve an existing collision.
Title: Re: Collision not working
Post by: fireside on February 20, 2008, 08:36:12 am
Way in front.  He starts at the middle of the platform.  And I can walk him all the way to the other side, turn around, and he goes through.  I know the block is doing collision.  It's combined, but I can drop the mouse from high up and it will stop on top the block if I move him over to where the block is when the program starts, so the move function isn't working for some reason.
Title: Re: Collision not working
Post by: EgonOlsen on February 20, 2008, 08:47:27 am
And the mouse is set to COLLISION_CHECK_SELF?
Title: Re: Collision not working
Post by: fireside on February 20, 2008, 09:00:22 am
Ha, you beat me to it.  I just tried that.  That's what it was.