Hello,
I am working on a bullet-hell game and am having problems with bullet collision detection. Essentially, it comes down to either inaccurate detection or unwanted behaviors.
Here are the methods I have tried:
- Adding
Collider2D
to the bullets and the player; addingRigidBody2D
to only the player with “Bullet” checked; adding a contact listener with the following code:
this.node.getComponent(Collider2D).on(Contact2DType.BEGIN_CONTACT, (self: Collider2D, other: Collider2D, contact: IPhysics2DContact | null) => {
console.log(other.node.name);
})
This method resulted in inaccurate collision detection (i.e., it prints the bullet node’s name when no bullet seems to overlap with the player)
- Building on Method 1, I added
RigidBody2D
, with “Bullet” checked, to all relevant nodes. This does give accurate results, but the bullets collide (an unwanted behavior) rather than overlap. In addition, it also introduced chaos into other nodes (due to the collisions), such as lasers. - Building on Method 2, I changed the collision layer of the bullets’
RigidBody2D
, but of course, this produced no collision callbacks. - I have also read some forum posts, but found no answer.
- I have also considered using
getBoundingBox()
, but due to the varied shapes of sprites, this method is not sensible.
Hence, how can I tackle this problem?
P.S. I am relatively new to Cocos Creator.