Hiya,
I’m engaged on a bullet-hell recreation and am having issues with bullet collision detection. Primarily, it comes right down to both inaccurate detection or undesirable behaviors.
Listed below are the strategies I’ve tried:
- Including
Collider2D
to the bullets and the participant; includingRigidBody2D
to solely the participant with “Bullet” checked; including a contact listener with the next code:
this.node.getComponent(Collider2D).on(Contact2DType.BEGIN_CONTACT, (self: Collider2D, different: Collider2D, contact: IPhysics2DContact | null) => {
console.log(different.node.title);
})
This technique resulted in inaccurate collision detection (i.e., it prints the bullet node’s title when no bullet appears to overlap with the participant)
- Constructing on Technique 1, I added
RigidBody2D
, with “Bullet” checked, to all related nodes. This does give correct outcomes, however the bullets collide (an undesirable conduct) relatively than overlap. As well as, it additionally launched chaos into different nodes (as a result of collisions), reminiscent of lasers. - Constructing on Technique 2, I modified the collision layer of the bullets’
RigidBody2D
, however after all, this produced no collision callbacks. - I’ve additionally learn some discussion board posts, however discovered no reply.
- I’ve additionally thought-about utilizing
getBoundingBox()
, however as a result of assorted shapes of sprites, this technique is senseless.
Therefore, how can I sort out this drawback?
P.S. I’m comparatively new to Cocos Creator.
So… I’ve made some progress. I modified RigidBody2D.Kind
to Kinematic
and “Permit Sleep” to false
, and now the bullets are overlapping and registering collisions appropriately. Nonetheless, might I ask whether or not or not this can affect efficiency considerably? (And why)