Author Topic: Mouse Collision Check!!  (Read 3196 times)

Offline Birdron

  • byte
  • *
  • Posts: 22
    • View Profile
Mouse Collision Check!!
« on: May 20, 2014, 12:50:28 pm »
Hi,
   I have to check two different collision in the game,
   1: Mouse<->plane
   2:Player<->wall

   Now, mouse is detecting both plane and wall, while I don't want the mouse to detect the wall. Player will never collide with plane, so that is not the problem.

   Is there a way to exclude the wall from mouse collision detection? The problem is, plane is below the wall. You can think the setup is "Diablo" like movement.

   Edit: Should the ellipsoid size be bigger then or equal to 1. My size is 0.5f. So, when player collides with wall, if I move the mouse left and right, it goes through the wall. My model size is: 0.1f, I had to scale it down. The movement speed is, 0.06f.

   My mouse detection method is based on the example of wiki.

   Thanks.
« Last Edit: May 20, 2014, 01:18:43 pm by Birdron »

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 12295
    • View Profile
    • http://www.jpct.net
Re: Mouse Collision Check!!
« Reply #1 on: May 20, 2014, 09:11:23 pm »
You can set objects to visible/invisible before the collision check. Invisible objects won't be checked.

Offline Birdron

  • byte
  • *
  • Posts: 22
    • View Profile
Re: Mouse Collision Check!!
« Reply #2 on: May 20, 2014, 10:33:34 pm »
Ok, I could not thought about it.

And could you give me some suggestion about my second question!

Thanks.

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 12295
    • View Profile
    • http://www.jpct.net
Re: Mouse Collision Check!!
« Reply #3 on: May 20, 2014, 11:08:11 pm »
I'm not sure what your second question exactly means. If it goes through the wall, something might be fishy with the way in which you are doing the collision detection. Or do you mean that it intersects with the wall, but doesn't pass through it?

Offline Birdron

  • byte
  • *
  • Posts: 22
    • View Profile
Re: Mouse Collision Check!!
« Reply #4 on: May 20, 2014, 11:55:15 pm »
My movement and collision is same like the ellipsoid collision example, here it is -
Code: [Select]
   // Player movement
   SimpleVector s = player.getPlayer().getZAxis();
   s.scalarMul(SPEED);
   moveRes.add(s);

   // avoid high speeds
   if (moveRes.length() > MAXSPEED) {
      moveRes.makeEqualLength(new SimpleVector(0, 0, MAXSPEED));
   }
   // Translate player
   player.getPlayer().translate(s);
   // Check player collision
   moveRes = player.getPlayer().checkForCollisionEllipsoid(moveRes, ellipsoid, 8);
   player.getPlayer().translate(moveRes);
   // damping
   if (moveRes.length() > DAMPING) {
      moveRes.makeEqualLength(new SimpleVector(0, 0, DAMPING));
   } else {
      moveRes = new SimpleVector(0, 0, 0);
   }

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 12295
    • View Profile
    • http://www.jpct.net
Re: Mouse Collision Check!!
« Reply #5 on: May 21, 2014, 08:28:19 am »
Ok, but that doesn't answer my question what the actual issue is!?

Offline Birdron

  • byte
  • *
  • Posts: 22
    • View Profile
Re: Mouse Collision Check!!
« Reply #6 on: May 21, 2014, 12:41:22 pm »
Can I pm u the runnable jar download link? I don't understand how I will explain the problem.

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 12295
    • View Profile
    • http://www.jpct.net
Re: Mouse Collision Check!!
« Reply #7 on: May 21, 2014, 12:57:43 pm »
Sure you can.

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 12295
    • View Profile
    • http://www.jpct.net
Re: Mouse Collision Check!!
« Reply #8 on: May 21, 2014, 09:27:42 pm »
I see...must have something to do with the way in which moveRes is being calculated. You are using the code from the example but you modified it. Now, you are translating the player two times. One is based on the actual collision detection result but the other one is based on the player's direction without any collision detection applied to it. That can't work. As a first step, i would simply remove this line

Code: [Select]
player.getPlayer().translate(s);

Apart from that, you might want to revisit this whole thing, because i'm not sure that this kind of stuff with damping and such is needed here. The most basic approach would be something like this:

Code: [Select]
   SimpleVector s = player.getPlayer().getZAxis();
   s.scalarMul(SPEED);
   s= player.getPlayer().checkForCollisionEllipsoid(s, ellipsoid, 8);
   player.getPlayer().translate(s);


Offline Birdron

  • byte
  • *
  • Posts: 22
    • View Profile
Re: Mouse Collision Check!!
« Reply #9 on: May 21, 2014, 11:27:06 pm »
Thank you, it is working perfectly now.