Author Topic: Collision not working  (Read 3098 times)

Offline fireside

  • double
  • *****
  • Posts: 605
    • View Profile
Collision not working
« 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:


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.
« Last Edit: February 20, 2008, 06:16:58 am by fireside »
click here->Fireside 7 Games<-

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 11748
    • View Profile
    • http://www.jpct.net
Re: Collision not working
« Reply #1 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?

Offline fireside

  • double
  • *****
  • Posts: 605
    • View Profile
Re: Collision not working
« Reply #2 on: February 20, 2008, 08:20:53 am »
He's in front of the block and walks right through it.
click here->Fireside 7 Games<-

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 11748
    • View Profile
    • http://www.jpct.net
Re: Collision not working
« Reply #3 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.

Offline fireside

  • double
  • *****
  • Posts: 605
    • View Profile
Re: Collision not working
« Reply #4 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.
« Last Edit: February 20, 2008, 08:39:16 am by fireside »
click here->Fireside 7 Games<-

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 11748
    • View Profile
    • http://www.jpct.net
Re: Collision not working
« Reply #5 on: February 20, 2008, 08:47:27 am »
And the mouse is set to COLLISION_CHECK_SELF?

Offline fireside

  • double
  • *****
  • Posts: 605
    • View Profile
Re: Collision not working
« Reply #6 on: February 20, 2008, 09:00:22 am »
Ha, you beat me to it.  I just tried that.  That's what it was.
click here->Fireside 7 Games<-