[Solved] Box2D Piercing Collision with Wall Bounce.

Anything libgdx related goes here!

[Solved] Box2D Piercing Collision with Wall Bounce.

Postby InvisibleNuke » Fri Sep 14, 2018 7:33 pm

Hello everyone,

Currently I am using a box2d world with its corresponding collision system.
However I am trying to achieve the following:

Image
A player that shoots a piercing bullet through an enemy that can bounch off the wall.
I have tried the following:
(1) setting the isSensor of the bullet to true, but that will result in the bullet not bouncing off the wall.
(2) creating a custom contactlistener for the world, but since you cannot deny a collision with that listener, the bullet will internally collide with the player shooting.
(3) using mask bits, so the bullet can only collide with the enemy and the wall, however if the bullet collides with the enemy it will bounce off (since it is not a sensor).

The problem I am having seems like a pretty generic problem, yet I can not find anything on this subject rather than simple masks.

If you have any question and or question, feel free to ask.
- Invisible.

Edit:
In my custom contact listener I also tried using contact.setEnabled(false) for piercing effect, however, this will result in bullets sometimes bouncing off the enemy, and bullets sometimes piercing the enemy. Which obviously is not a good option if the effect will be random.
Last edited by InvisibleNuke on Fri Sep 14, 2018 9:20 pm, edited 1 time in total.
InvisibleNuke
 
Posts: 9
Joined: Sat Oct 07, 2017 10:55 am

Re: Box2D Piercing Collision with Wall Bounce.

Postby evilentity » Fri Sep 14, 2018 8:53 pm

Add sensor to the enemy and make bullet interact with it. Now you know when bullet hits it and it can collide with walls.
Looking for a freelancer? PM me!
evilentity
 
Posts: 4427
Joined: Wed Aug 24, 2011 11:37 am

Re: Box2D Piercing Collision with Wall Bounce.

Postby InvisibleNuke » Fri Sep 14, 2018 9:20 pm

Ah thanks, so basically I was setting the sensor to the wrong object, instead of setting the sensor to the bullet, I need to make an extra hitbox that deals with the hitboxes.

Thanks for the quick response!
[Closed]
InvisibleNuke
 
Posts: 9
Joined: Sat Oct 07, 2017 10:55 am


Return to Libgdx

Who is online

Users browsing this forum: Google [Bot] and 1 guest